# Calculate Rectangle Area Using Java Example

by Dinesh Thakur Category: Data Type

In the Following example AreaofRectangleExample shows how to Calculate Area of Rectangle is length * width.

```import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader; public class AreaofRectangleExample       // Declaring class name as AreaofRectangleExample {        public static void main(String[] args)               {                               int width = 0;                int length = 0;                                       try                              {                        //Obtaining the keyboard input with BufferedReaderBufferedReader Buffer = new BufferedReader(new InputStreamReader(System.in));                                               System.out.print("Please enter the length of Rectangle : ");                        length = Integer.parseInt(Buffer.readLine());                        System.out.print("Please enter the width of Rectangle : ");                        width = Integer.parseInt(Buffer.readLine());                       //Perform Calculations and Display Result                       int AreaofRectangle = length * width;                       System.out.println("Area of Rectangle is " + AreaofRectangle);               }              catch(IOException e)                  {                        System.out.println("Input Error :" + e);                        System.exit(0);                }      }               }
```

In above program, two integers length and width are defined and are assigned the value 12 and 13 respectively. These variables are then multiplied to calculate area which is stored in variable AreaofRectangle and then it is displayed.

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article