1// calculate area of rectangle using class in java
2import java.io.*;
3class RectangleShape
4{
5 int length, breadth;
6 void setValue(int l, int b)
7 {
8 length = l;
9 breadth = b;
10 }
11 // get area of rectangle
12 int findArea()
13 {
14 return (length * breadth);
15 }
16}
17public class RectangleAreaDemo
18{
19 public static void main(String[] args)
20 {
21 RectangleJava obj = new RectangleJava();
22 obj.setValue(10, 5);
23 System.out.println("Area of rectangle: " + obj.findArea());
24 }
25}
1import java.util.Scanner;
2public class RectangleArea
3{
4 public static void main(String[] args)
5 {
6 Scanner sc = new Scanner(System.in);
7 System.out.println("Please enter length of rectangle: ");
8 double length = sc.nextDouble();
9 System.out.println("Please enter width of rectangle: ");
10 double width = sc.nextDouble();
11 double area = length * width;
12 System.out.println("Area of rectangle is: " + area);
13 sc.close();
14 }
15}