Guest User

Untitled

a guest
Jan 12th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class Triangle {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. System.out.println("Enter the sides of the triangle:\n");
  9. Scanner sc = new Scanner(System.in);
  10. double a = sc.nextDouble();
  11. double b = sc.nextDouble();
  12. double c = sc.nextDouble();
  13.  
  14. int x = 0;
  15. if(a==b) x++;
  16. if(b==c) x++;
  17. if(c==a) x++;
  18.  
  19. // to solve the problem we count the number of equal sides.
  20. // if x=0, all sides are different.
  21. // if x=1, two sides are equal.
  22. // if x=3, all sides are equal.
  23. // x can not be 2!
  24.  
  25. // the length of any side must be smaller than the sum of two other sides.
  26. if(a >= (b+c) || c >= (b+a) || b >= (a+c) )
  27. System.out.println("It is Not a triangle.");
  28. else if (x==0)
  29. System.out.println("The triangle is scalene.");
  30. else if (x==1)
  31. System.out.println("The triangle is isosceles.");
  32. else if (x==3)
  33. System.out.println("The triangle is equilateral.");
  34.  
  35. }
  36.  
  37. }
Add Comment
Please, Sign In to add comment