Consider the following Java program in which the statements are in the incorrect
ID: 3730293 • Letter: C
Question
Consider the following Java program in which the statements are in the incorrect order. Rearrange the statements so that it prompts the user to input the length and width of a rectangle and output the area and perimeter of the rectangle.
public class Ch2_PrExercise5 { static Scanner console = new Scanner(System.in); import java.util.*; { public static void main(String[] args) int width; System.out.print("Enter the length: "); width = console.nextInt(); System.out.println(); int length; System.out.print("Enter the width: "); length = console.nextInt(); System.out.println(); area = length * width; System.out.println("Area = " + area); System.out.println("Perimeter = " + perimeter); perimeter = 2 * (length + width); int area; int perimeter; } }
Explanation / Answer
import java.util.*;
public class Ch2_PrExercise5
{
static Scanner console = new Scanner(System.in);
{
public static void main(String[] args)
int width;
int length;
System.out.print("Enter the width: ");
width = console.nextInt();
System.out.println();
System.out.print("Enter the length: ");
length = console.nextInt();
System.out.println();
int area;
int perimeter;
area = length * width;
perimeter = 2 * (length + width);
System.out.println("Area = " + area);
System.out.println("Perimeter = " + perimeter);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.