-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTriangle.java
More file actions
30 lines (27 loc) · 774 Bytes
/
Triangle.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
public class Triangle {
private double area;
private int height;
private int length;
public static void main(String[] args) {
int x = 0;
Triangle[] ta = new Triangle[4];
while (x < 4) {
ta[x] = new Triangle();
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;
}
int y = x;
x = 27;
Triangle t5 = ta[2];
ta[2].area = 343;
System.out.print("y = " + y);
System.out.println(", area t5 = " + t5.area);
}
private void setArea() {
area = (height * length) / 2;
}
}