- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTriangle.java
More file actions
Latest commit
30 lines (27 loc) · 774 Bytes
/
Copy pathTriangle.java
File metadata and controls
30 lines (27 loc) · 774 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
publicclassTriangle {
privatedoublearea;
privateintheight;
privateintlength;
publicstaticvoidmain(String[] args) {
intx = 0;
Triangle[] ta = newTriangle[4];
while (x < 4) {
ta[x] = newTriangle();
ta[x].height = (x + 1) * 2;
ta[x].length = x + 4;
ta[x].setArea();
System.out.print("triangle " + x + ", area");
System.out.println(" = " + ta[x].area);
x = x + 1;
}
inty = x;
x = 27;
Trianglet5 = ta[2];
ta[2].area = 343;
System.out.print("y = " + y);
System.out.println(", area t5 = " + t5.area);
}
privatevoidsetArea() {
area = (height * length) / 2;
}
}