Java Program to Calculate the Area of Rectangle

Java program to calculate the  area of a rectangle using Scanner classes:

import java.util.Scanner;

public class Rarea

{

public static void main(String[] args)

{

Scanner inn = new Scanner(System.in);

double height, width, area;

System.out.println(“Area of Rectangle”);

System.out.print(“Please enter the height: “);

height = inn.nextDouble();

System.out.print(“Please enter the width: “);

width = inn.nextDouble();

area = height * width;

System.out.println(“Area: ” + area);

}

}

In the above program, the user enters the width and height of the rectangle. The rectangle area can be found by multiplying the width by the height.

The formula for the area is:

Area = width * height

The output of the above program is:

 

Calculate the Area of the Rectangle using the Scanner class
Calculate the Area of the Rectangle using the Scanner class
Calculate the Area of the Rectangle using the Scanner class

Area:600.0  result is shown in floating points because in the program we declare the variables width, height, and area as double. We use double data types. For example, if we have a double value, then

Java program to calculate the area of a rectangle

class Rarea1 {

public static void main (String[] args)

{

double length = 22.3;

double width = 24.6;

double area = length*width;

System.out.println(“Area of Rectangle is:”+area);

}

}

The output of the above program is:

Calculate the area of the rectangle
Calculate the area of the rectangle
Calculate the area of the rectangle without using the Scanner class

Java program to convert Fahrenheit scale to Celsius

Java Program To Swap Two Numbers