Java Program to Find the Area of Rectangle - The Coding Shala
Home >> Java Programs >> Area of Rectangle
Other Posts You May Like
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
- Java Program to Find the Area of Circle
- Java Program to Find the Area of Triangle
- Java Program to Swap two Numbers
- Java Program to Add Two Numbers
- Java Program to Find the Sum of Digits of a Number
Comments
Post a Comment