Created
September 20, 2024 23:09
-
-
Save vdeemann/29f06177c3b739abed07e71b5c429130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Triangle { | |
double area; | |
int height; | |
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(", t5 area = " + t5.area); | |
} | |
void setArea() { | |
area = (height * length) / 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment