vencinachev

Triangle-Java

Mar 22nd, 2021
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.util.Scanner;
  2. class TriangleCalc {
  3.   public static void main(String[] args){
  4.      Scanner scan = new Scanner(System.in);
  5.      double a, b, c, p, P, S;
  6.      System.out.print("Enter a: ");
  7.      a = scan.nextDouble();
  8.      System.out.print("Enter b: ");
  9.      b = scan.nextDouble();
  10.      System.out.print("Enter c: ");
  11.      c = scan.nextDouble();
  12.     if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || a + c <= b || b + c <= a){
  13.        System.out.println("Invalid triangle!");
  14.        return;
  15.      }
  16.      
  17.      P = a + b + c;
  18.      p = P / 2;
  19.      S = Math.sqrt(p*(p-a)*(p-b)*(p-c));
  20.      System.out.printf("P = %.2f\n", P);
  21.      System.out.printf("S = %.2f\n", S);
  22.   }
  23. }
Add Comment
Please, Sign In to add comment