SHARE
TWEET

Untitled

a guest Oct 19th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package maman11;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Triangle
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         Scanner scan = new Scanner(System.in);
  10.         System.out.println("This program calculates the area and the perimeter of given triangle.");
  11.         System.out.println("Please enter thr three lengths of the triangle's sides");
  12.  
  13.         int a = scan.nextInt();
  14.         int b = scan.nextInt();
  15.         int c = scan.nextInt();
  16.  
  17.         int perimeter = a + b + c;
  18.         double s = perimeter / 2.0;
  19.         double sqrtExpression = s * (s - a) * (s - b) * (s - c);
  20.         String errorValues = "";
  21.  
  22.         if (a <= 0)
  23.             errorValues += "\na: " + a;
  24.         if (b <= 0)
  25.             errorValues += "\nb: " + b;
  26.         if (c <= 0)
  27.             errorValues += "\nc: " + c;
  28.  
  29.         if (!errorValues.equals(""))
  30.         {
  31.             System.out.println("The triangle's edges can't be negative");
  32.             System.out.println("The invalid enges are: " + errorValues);
  33.         }
  34.         else
  35.         {
  36.             if (a + b < c)
  37.                 errorValues += "\na: " + a + "\nb: " + b + "\n" + a + " + " + b + " >=! " + c;
  38.             else if (a + c < b)
  39.                 errorValues += "\na: " + a + "\nc: " + c + "\n" + a + " + " + c + " >=! " + b;
  40.             else if (b + c < a)
  41.                 errorValues += "\nb: " + b + "\nc: " + c + "\n" + b + " + " + c + " >=! " + a;
  42.  
  43.             if (!errorValues.equals(""))
  44.             {
  45.                 System.out.println("The triangle inequality isn't fulfill");
  46.                 System.out.println("The invalid enges are: " + errorValues);
  47.             }
  48.             else
  49.             {
  50.                 System.out.println("perimeter: " + perimeter);
  51.                 System.out.println("area: " + Math.sqrt(sqrtExpression));
  52.             }
  53.         }  
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top