Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. package triangle.type.broc.east;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TriangleTypeBrocEast
  6. {
  7.  
  8. public static void main(String[] args)
  9. {
  10. {
  11. Scanner in=new Scanner(System.in);
  12. int a,b,c;
  13. System.out.print("Enter the 1st side of a triangle(0 when done): ");
  14. a=in.nextInt();
  15. while(a!=0)
  16. {
  17. System.out.print("Enter the 2nd side of the triangle: ");
  18. b=in.nextInt();
  19. System.out.print("Enter the 3rd side of the triangle: ");
  20. c=in.nextInt();
  21. System.out.println("The triangle is "+triangleType(a,b,c));
  22. System.out.print("nEnter the 1st side of a triangle(0 when done): ");
  23. a=in.nextInt();
  24. }
  25. }
  26.  
  27.  
  28. public static String triangleType(int num1,int num2,int num3)
  29. {
  30. int a,b,c;
  31. if(num1<num2)
  32. {
  33. if(num1<num3)
  34. {
  35. a=num1; //num1 is smallest
  36. if(num2<num3)
  37. { b=num2;
  38. c=num3;
  39. }
  40. else
  41. { b=num3;
  42. c=num2;
  43. }
  44. }
  45. else //num3 is smallest
  46. { a=num3;
  47. b=num1;
  48. c=num2;
  49. }
  50. }
  51. else //num2 or num3 smallest
  52. if(num2<num3)
  53. { a=num2; //num2 smallest
  54. if(num1<num3)
  55. { b=num1;
  56. c=num3;
  57. }
  58. else
  59. { b=num3;
  60. c=num1;
  61. }
  62. }
  63. else
  64. { a=num3;
  65. b=num2;
  66. c=num1;
  67. }
  68. if(a+b<=c)
  69. return "INVALID TRIANGLE";
  70. if(a==c)
  71. return "EQUILATERAL";
  72. if(a==b||b==c)
  73. return "ISOSCELES";
  74. return "SCALENE";
  75.  
  76.  
  77. }
  78. }
  79.  
  80. public static String triangleType(int num1,int num2,int num3)
  81. {
  82. int a,b,c;
  83. if(num1<num2)
  84. {
  85. if(num1<num3)
  86. {
  87. a=num1; //num1 is smallest
  88. if(num2<num3)
  89. {
  90. b=num2;
  91. c=num3;
  92. }
  93. else
  94. {
  95. b=num3;
  96. c=num2;
  97. }
  98. }
  99. else //num3 is smallest
  100. {
  101. a=num3;
  102. b=num1;
  103. c=num2;
  104. }
  105. }
  106. else //num2 or num3 smallest
  107. { // You Forgot this one
  108. if(num2<num3)
  109. {
  110. a=num2; //num2 smallest
  111. if(num1<num3)
  112. {
  113. b=num1;
  114. c=num3;
  115. }
  116. else
  117. {
  118. b=num3;
  119. c=num1;
  120. }
  121. }
  122. else
  123. {
  124. a=num3;
  125. b=num2;
  126. c=num1;
  127. }
  128. } // You Forgot this one
  129. if(a+b<=c)
  130. return "INVALID TRIANGLE";
  131. if(a==c)
  132. return "EQUILATERAL";
  133. if(a==b||b==c)
  134. return "ISOSCELES";
  135. return "SCALENE";
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement