Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package triangle.type.broc.east;
- import java.util.Scanner;
- public class TriangleTypeBrocEast
- {
- public static void main(String[] args)
- {
- {
- Scanner in=new Scanner(System.in);
- int a,b,c;
- System.out.print("Enter the 1st side of a triangle(0 when done): ");
- a=in.nextInt();
- while(a!=0)
- {
- System.out.print("Enter the 2nd side of the triangle: ");
- b=in.nextInt();
- System.out.print("Enter the 3rd side of the triangle: ");
- c=in.nextInt();
- System.out.println("The triangle is "+triangleType(a,b,c));
- System.out.print("nEnter the 1st side of a triangle(0 when done): ");
- a=in.nextInt();
- }
- }
- public static String triangleType(int num1,int num2,int num3)
- {
- int a,b,c;
- if(num1<num2)
- {
- if(num1<num3)
- {
- a=num1; //num1 is smallest
- if(num2<num3)
- { b=num2;
- c=num3;
- }
- else
- { b=num3;
- c=num2;
- }
- }
- else //num3 is smallest
- { a=num3;
- b=num1;
- c=num2;
- }
- }
- else //num2 or num3 smallest
- if(num2<num3)
- { a=num2; //num2 smallest
- if(num1<num3)
- { b=num1;
- c=num3;
- }
- else
- { b=num3;
- c=num1;
- }
- }
- else
- { a=num3;
- b=num2;
- c=num1;
- }
- if(a+b<=c)
- return "INVALID TRIANGLE";
- if(a==c)
- return "EQUILATERAL";
- if(a==b||b==c)
- return "ISOSCELES";
- return "SCALENE";
- }
- }
- public static String triangleType(int num1,int num2,int num3)
- {
- int a,b,c;
- if(num1<num2)
- {
- if(num1<num3)
- {
- a=num1; //num1 is smallest
- if(num2<num3)
- {
- b=num2;
- c=num3;
- }
- else
- {
- b=num3;
- c=num2;
- }
- }
- else //num3 is smallest
- {
- a=num3;
- b=num1;
- c=num2;
- }
- }
- else //num2 or num3 smallest
- { // You Forgot this one
- if(num2<num3)
- {
- a=num2; //num2 smallest
- if(num1<num3)
- {
- b=num1;
- c=num3;
- }
- else
- {
- b=num3;
- c=num1;
- }
- }
- else
- {
- a=num3;
- b=num2;
- c=num1;
- }
- } // You Forgot this one
- if(a+b<=c)
- return "INVALID TRIANGLE";
- if(a==c)
- return "EQUILATERAL";
- if(a==b||b==c)
- return "ISOSCELES";
- return "SCALENE";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement