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

Write a program that will calculate the perimeter and area of a rectangle. Promp

ID: 3789993 • Letter: W

Question

Write a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter.IN JAVA

Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code.

Run your program twice using different inputs in JGrasp. Copy the output and place it at the bottom of the .java class file as comments OR copy the output to a Word document and submit with the class.

Explanation / Answer

//name, date,
// Java program to calculate Area and Perimeter of a Rectangle
import java.util.*; //scanner class in util

public class Rectangle
{
   public static void main (String[] args)
   {
       Scanner scan = new Scanner(System.in);//use Scanner class object to input length and width
      
       System.out.println("Enter Length and Width of Rectangle :");
      
       int length = scan.nextInt();// nextInt(0 method of Scanner Class is used to input integer values for length and width)
       int width = scan.nextInt();
      
       int area = length * width; //compute area
       int perimeter = 2*length +2*width; //compute perimeter
      
       System.out.println("Area of Rectangle : "+area); //display area and perimeter
       System.out.println("Perimeter of Rectangle : "+perimeter);
     
   }
}

Output

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