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 BufferedReader
BufferedReader 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.