Write a program that will calculate the perimeter and area o

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.

Solution

//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

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.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site