67 224
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #4078 in Java | JSP | JSF for Jone

Question #4078
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
System.out.print("Enter the value of a: ");
int a = console.nextInt();
System.out.print("Enter the value of b: ");
int b = console.nextInt();
System.out.print("Enter the value of h: ");
int h = console.nextInt();
double area = (a + b) * h / 2;
System.out.println("Area = " + "(" + a + " + " + b + ")" + " * " + h + " / " + 2 );
System.out.println("Area = " + area);
if ( a > 0 || b > 0 || h > 0)
break;
int count = 0;
for (; n = area; n++)
{
count++;
}
System.out.println("The number of trapezium calculated: " + count);
System.out.println("End.");
}
How do I use scanner for this code and calculate & print the area of the trapezium as many time until the user key in a non-positive input.
Expert's answer
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
int count = 0;
while(true)
{
System.out.print("Enter the value of a: ");
int a = console.nextInt();
if (a <= 0) break;
System.out.print("Enter the value of b: ");
int b = console.nextInt();
if (b <= 0) break;
System.out.print("Enter the value of h: ");
int h = console.nextInt();
if (h <= 0) break;
double area = (a + b) * h / 2;
count++;
System.out.println("Area = " + "(" + a + " + " + b + ")" + " *
" + h + " / " + 2 );
System.out.println("Area = " + area);
System.out.println("The number of trapezium calculated: " +
count);
System.out.println("End.");
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions