Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class TriangleCalc {
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- double a, b, c, p, P, S;
- System.out.print("Enter a: ");
- a = scan.nextDouble();
- System.out.print("Enter b: ");
- b = scan.nextDouble();
- System.out.print("Enter c: ");
- c = scan.nextDouble();
- if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || a + c <= b || b + c <= a){
- System.out.println("Invalid triangle!");
- return;
- }
- P = a + b + c;
- p = P / 2;
- S = Math.sqrt(p*(p-a)*(p-b)*(p-c));
- System.out.printf("P = %.2f\n", P);
- System.out.printf("S = %.2f\n", S);
- }
- }
Add Comment
Please, Sign In to add comment