In: Computer Science
User the Scanner class for your input
Write a java program to calculate the area of a rectangle.
Rectangle Area is calculated by multiplying the length by the width
display the output as follow:
Length =
Width =
Area =
Load:
1. Design (Pseudocode )
2. Source file (Java file, make sure to include comments)
3. Output file (word or pdf or jpig file)
/******* RectangleDemo.java ********/
import java.util.Scanner;
public class RectangleDemo {
public static void main(String[] args) {
// Declaring variables
double length, width, area;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
// Getting the input entered by
the user
System.out.print("Enter length of
rectangle :");
length = sc.nextDouble();
System.out.print("Enter width of
rectangle :");
width = sc.nextDouble();
area = length * width;
// Displaying the output
System.out.printf("Length =
%.2f\n", length);
System.out.printf("Width = %.2f\n",
width);
System.out.printf("Area = %.2f\n",
area);
}
}
/**************************************************/
/**************************************************/
Output:
/**************************************************/