ADVERTISEMENT
ADVERTISEMENT

Java program to find Area of Rectangle

Area of Rectangle in Java - This program will read length and width of the Rectangle and Calculate Area of the Rectangle.

To find Area of the Rectangle - Multiply Rectangle Length with Rectangle Width.

Area of Rectangle using Java program

//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);    
         
     }
}

Output

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

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

Using Function/Method

//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);    
         
     }
}

Core Java Example Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.