Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote