Java Program to Find the Area of Rectangle - The Coding Shala

Home >> Java Programs >> Area of Rectangle

 In this post, we will learn how to write a Java Program to Find the Area of a Rectangle.

Java Program to Find the Area of Rectangle

The length and width of a rectangle are given to us, find the total area of the rectangle using a Java Program.

Area of Rectangle = length * width

Example 1:
Input: length = 2
           width = 8
Output: Area = 16

Java Program

// Java program to Find Area of Rectangle

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
		
		// take length input
		System.out.println("Enter the length of rectangle");
		double length = sc.nextDouble();
		
		// take width input
		System.out.println("Enter the width of rectangle");
		double width = sc.nextDouble();		
		
		// calculate the area
		// area = length * width
		double area = length * width;
		System.out.println("Area of Rectangle is: " + area);
		
		sc.close();
	}
}

Output: 

Enter the length of rectangle
2
Enter the width of rectangle
8
Area of Rectangle is: 16.0


Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.

Comments

Popular Posts from this Blog

N-th Tribonacci Number Solution - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

LeetCode - Shuffle the Array Solution - The Coding Shala

LeetCode - Swap Nodes in Pairs Solution - The Coding Shala