Crenox

Triangle Program

Jan 29th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package samkough.main;
  2.  
  3. public class Triangle
  4. {
  5. double area;
  6. int height;
  7. int length;
  8.  
  9. public static void main(String argsp[])
  10. {
  11. int x = 0;
  12. Triangle[] ta = new Triangle[4];
  13. while (x < 4)
  14. {
  15. ta[x] = new Triangle();
  16. ta[x].height = (x + 1) * 2;
  17. ta[x].length = x + 4;
  18. ta[x].setArea();
  19.  
  20. System.out.print("triangle " + x + ", area");
  21. System.out.println(" = " + ta[x].area);
  22. x = x + 1;
  23. }
  24. int y = x;
  25. x = 27;
  26. Triangle t5 = ta[2];
  27. ta[2].area = 343;
  28. System.out.print("y = " + y);
  29. System.out.println(", t5 area = " + t5.area);
  30. }
  31.  
  32. void setArea()
  33. {
  34. area = (height * length) / 2;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment