- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
Latest commit
37 lines (28 loc) · 663 Bytes
/
Copy pathRectangle.java
File metadata and controls
37 lines (28 loc) · 663 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
31
32
33
34
35
36
37
classrect {
publicstaticvoidmain(Stringargs[]) {
Rectangler1 = newRectangle();
System.out.println("Area of r1: " + r1.area());
Rectangler2 = newRectangle(20, 30);
System.out.println("Area of r2: " + r2.area());
Rectangler3 = newRectangle(10);
System.out.println("Area of r3: " + r3.area());
}
}
classRectangle {
intlength, width;
Rectangle() {
this.length = 0;
this.width = 0;
}
Rectangle(intlength, intwidth) {
this.length = length;
this.width = width;
}
Rectangle(intlength) {
this.length = length;
this.width = length;
}
intarea() {
returnlength * width;
}
}