Advertisement
desislava_topuzakova

03.Triangle

Mar 11th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package TestJan;
  2.  
  3. import java.text.DecimalFormat;
  4.         import java.util.Scanner;
  5.  
  6. public class Triangle {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         DecimalFormat decimalFormat = new DecimalFormat("0.#");
  11.  
  12.         double a = Double.parseDouble(scanner.nextLine());
  13.         double b = Double.parseDouble(scanner.nextLine());
  14.         double c = Double.parseDouble(scanner.nextLine());
  15.  
  16.         boolean checkIsTriangle = !((a < b + c) && (b < a + c) && (c < a + b));
  17.         boolean checkIsScalene = (a != b && b != c && a != c);
  18.         boolean checkIsIsosceles = ((a == b || b == c || a == c) && (a != b || b != c || a != c));
  19.         boolean checkIsEquilateral = (a == b && b == c && a == c);
  20.  
  21.         if (checkIsTriangle) {
  22.             System.out.println("There is no triangle with sides " + decimalFormat.format(a) + ", " + decimalFormat.format(b) + " and " + decimalFormat.format(c)+".");
  23.         } else if (checkIsScalene) {
  24.             System.out.println("Triangle with sides " + decimalFormat.format(a) + ", " + decimalFormat.format(b) + " and " + decimalFormat.format(c) + " is scalene.");
  25.         } else if (checkIsIsosceles) {
  26.             System.out.println("Triangle with sides " + decimalFormat.format(a) + ", " + decimalFormat.format(b) + " and " + decimalFormat.format(c) + " is isosceles.");
  27.  
  28.         } else if (checkIsEquilateral) {
  29.             System.out.println("Triangle with sides " + decimalFormat.format(a) + ", " + decimalFormat.format(b) + " and " + decimalFormat.format(c) + " is equilateral.");
  30.  
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement