Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class Triangle {
- public static void main(String[] args) {
- System.out.println("Enter the sides of the triangle:\n");
- Scanner sc = new Scanner(System.in);
- double a = sc.nextDouble();
- double b = sc.nextDouble();
- double c = sc.nextDouble();
- int x = 0;
- if(a==b) x++;
- if(b==c) x++;
- if(c==a) x++;
- // to solve the problem we count the number of equal sides.
- // if x=0, all sides are different.
- // if x=1, two sides are equal.
- // if x=3, all sides are equal.
- // x can not be 2!
- // the length of any side must be smaller than the sum of two other sides.
- if(a >= (b+c) || c >= (b+a) || b >= (a+c) )
- System.out.println("It is Not a triangle.");
- else if (x==0)
- System.out.println("The triangle is scalene.");
- else if (x==1)
- System.out.println("The triangle is isosceles.");
- else if (x==3)
- System.out.println("The triangle is equilateral.");
- }
- }
Add Comment
Please, Sign In to add comment