Java Program to Find Area of Rectangle

You are currently viewing Java Program to Find Area of Rectangle

Java program to find Area of Rectangle

//Java program to find Area of Rectangle.
 
import java.util.*;
 
public class AreaRectangle{
 
     public static void main(String []args){
        double length,width,area;
         
        Scanner sc=new Scanner(System.in);
         
        //Read Length and Width of Rectangle
        System.out.print("Enter length: ");
        length=sc.nextDouble();
        System.out.print("Enter width: ");
        width=sc.nextDouble();
         
        //Calculate Area 
        area= length*width;
         
        //Print Result
        System.out.println("Area of Rectangle: " + area);    
         
     }
}
//Java program to find Area of Rectangle.
 
import java.util.*;
 
public class AreaRectangle{
 
    //Function to find Area of Rectangle
    public static double AreaOfRectangle(double l, double w)
    {
        double area;
        area=l*w;
        return area;
    }
     
     public static void main(String []args){
        double length,width,area;
         
        Scanner sc=new Scanner(System.in);
         
        //Read Length and Width of Rectangle
        System.out.print("Enter length: ");
        length=sc.nextDouble();
        System.out.print("Enter width: ");
        width=sc.nextDouble();
         
        //Find Area - Calling Functionn
        area= AreaOfRectangle(length, width);
         
        //Print Result
        System.out.println("Area of Rectangle: " + area);    
         
     }
}

Output

    [email protected]:~$ javac AreaRectangle.java
    [email protected]:~$ java AreaRectangle

    Enter length: 10.2
    Enter width: 20.3 
    Area of Rectangle: 207.06

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply