0% found this document useful (0 votes)
28 views2 pages

Java BufferedReader Rectangle Area Example

This Java program calculates the area of a rectangle by prompting the user to input the length and width, multiplying those values, and printing the result. It handles invalid input exceptions. The program demonstrates how to calculate the area of a rectangle using its length and width in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Java BufferedReader Rectangle Area Example

This Java program calculates the area of a rectangle by prompting the user to input the length and width, multiplying those values, and printing the result. It handles invalid input exceptions. The program demonstrates how to calculate the area of a rectangle using its length and width in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

/*

2.
3.
4.

Calculate Rectangle Area using Java Example


This Calculate Rectangle Area using Java Example shows how to calculate
area of Rectangle using it's length and width.

5.*/

6.
[Link] [Link];
[Link] [Link];
[Link] [Link];

10.
[Link] class CalculateRectArea {

12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.

public static void main(String[] args) {

int width = 0;
int length = 0;

try
{
//read the length from console
BufferedReader br = new BufferedReader(newInputStreamReader([Link]));

[Link]("Please enter length of a rectangle");


length = [Link]([Link]());

//read the width from console


[Link]("Please enter width of a rectangle");
width = [Link]([Link]());

}
//if invalid value was entered
catch(NumberFormatException ne)
{
[Link]("Invalid value" + ne);
[Link](0);
}
catch(IOException ioe)
{

40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.

[Link]("IO Error :" + ioe);


[Link](0);
}

/*
* Area of a rectangle is
* length * width
*/

int area = length * width;

[Link]("Area of a rectangle is " + area);


}

54.}

55.
56./*
[Link] of Calculate Rectangle Area using Java Example would be
[Link] enter length of a rectangle
59.10
[Link] enter width of a rectangle
61.15
[Link] of a rectangle is 150
63.*/

You might also like