Java program to find area of rectangle using class and object

Hey guys!! Welcome to flower brackets blog. Let’s learn java program to find area of rectangle using class and object.

Also read – rectangle java program

Java program to find area of rectangle using class and object

Java program to find area of rectangle using class and object

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class RectangleShape 
{
int length, breadth;
void setvalues(int l, int b)
{
length = l;
breadth = b;
}
int findArea()
{
return(length * breadth);
}
};
public class RectangleAreaDemo
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
int a, b;
RectangleShape rs = new RectangleShape();
System.out.println("Please enter length and breadth : ");
str = br.readLine();
a = Integer.parseInt(str);
str = br.readLine();
b = Integer.parseInt(str);
rs.setvalues(a, b);
System.out.println("Area of rectangle : " + rs.findArea());
}
}

Output:

Please enter length and breadth :
5
2
Area of rectangle : 10

Related Posts