Java Area of a Rectangle Program is an easy program to do if you know your basics of geometry. As a beginner of java programmer you can write it as set of a few Java statements without any conditional or looping constructs.
The program presented here as an example reads the length and the width of the rectangle from the user and returns the area of the rectangle using the following formula.
Area of rectangle = length * width
Area of a Rectangle
Let’s see how the above formula is implemented in java program to find the area of a rectangle.
import java.util.Scanner; public class RectArea { public static void main(String[] args) { Scanner scObj= new Scanner(System.in); //Read Length value from user System.out.println("Enter the length of the rectangle"); int intLength = scObj.nextInt(); //Read width value from user System.out.println("Enter the width of the rectangle"); int intWidth = scObj.nextInt(); //Calculate area of rectangle int rectArea= intLength*intWidth; System.out.println(rectArea + " is area of a Rectangle with length="+intLength +" and width=" +intWidth); } }