Write a Java program to print the area and perimeter of a rectangle

This example will provide how to print the area and perimeter of a rectangle in Java.

package octopuscodes.com.demo;

import java.util.Scanner;

public class Demo {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		System.out.print("a: ");
		double a = scanner.nextDouble();
		System.out.print("b: ");
		double b = scanner.nextDouble();

		double area = a * b;
		double perimeter = (a + b) * 2;

		System.out.println("Area : " + area);
		System.out.println("Perimeter : " + perimeter);

	}

}
a: 3
b: 10
Area : 30.0
Perimeter : 26.0