logo image

Java program to calculate rectangle area and circumference

Following program shows you how to calculate rectangle area and circumference. This program gets rectangle length and width from user and calculates area and circumference and prints them using following formulas Area = length X width Circumference = 2 X length + 2 X width

import java.util.Scanner;

public class MathGeometry3 {

	public static void main(String[] args) {

		double rectangleLength;
		double rectangleWidth;

		Scanner in = new Scanner(System.in);

		System.out.println("Enter length of rectangle:");
		rectangleLength= in.nextInt();

		System.out.println("Enter width of rectangle:");
		rectangleWidth = in.nextInt();

		double areaOfRectangle = rectangleLength * rectangleWidth ;
		System.out.println("Area of rectangle is: " + areaOfRectangle);

		double circumferenceOfRectangle = 2 * (rectangleLength) + 2 * (rectangleWidth);
		System.out.println("Circumference of rectangle is: " + circumferenceOfRectangle);


Enter length of rectangle:
Enter width of rectangle:
Area of rectangle is: 3000.0
Circumference of rectangle is: 220.0