Java help Requirements: A program is needed that inputs values for x, y, and z a
ID: 3784807 • Letter: J
Question
Java help
Requirements: A program is needed that inputs values for x, y, and z and calculates a result for the indicated formula. If the product of x, y, and z is zero, the result is zero. Design: The result should be calculated as follows: result = (2x - 7.4) (4 y + 9.3) (6 z - 11.2)/xyz for xyz notequalto 0 Special case: result = 0 for xyz = 0 Three examples of program output for the indicated input values are shown below. Note that lines 2 through 4 for the input values begin with tab which is equivalent to three spaces in jGRASP (i.e., your output should use the escape sequence for a tab)Explanation / Answer
import java.util.Scanner;
public class formulaGiven {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println("result = (2x-7.4)(4x+9.3)(6z-11.2)/xyz");
System.out.print("Enter x: ");
double x = scan.nextDouble();
System.out.print("Enter y: ");
double y = scan.nextDouble();
System.out.print("Enter z: ");
double z = scan.nextDouble();
if(x*y*z==0)
{
System.out.println("result = 0.0");
}
else
{
double result = (2*x-7.4)*(4*x+9.3)*(6*z-11.2);
result = result/(x*y*z);
System.out.print("result = "+result);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.