-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangleArea.java
More file actions
30 lines (25 loc) · 847 Bytes
/
RectangleArea.java
File metadata and controls
30 lines (25 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
public class RectangleArea {
public static class Rectangle {
float length;
float breadth;
public Rectangle(float length, float breadth) {
this.length = length;
this.breadth = breadth;
}
public float area() {
return this.length * this.breadth;
}
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter length of a rectangle: ");
float length = sc.nextFloat();
System.out.print("Enter breadth of a rectangle: ");
float breadth = sc.nextFloat();
sc.close();
Rectangle rectangle_obj = new Rectangle(length, breadth);
float area = rectangle_obj.area();
System.out.println("Area of rectangle: " + area);
}
}