Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package maman11;
- import java.util.Scanner;
- public class Triangle
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("This program calculates the area and the perimeter of given triangle.");
- System.out.println("Please enter thr three lengths of the triangle's sides");
- int a = scan.nextInt();
- int b = scan.nextInt();
- int c = scan.nextInt();
- int perimeter = a + b + c;
- double s = perimeter / 2.0;
- double sqrtExpression = s * (s - a) * (s - b) * (s - c);
- String errorValues = "";
- if (a <= 0)
- errorValues += "\na: " + a;
- if (b <= 0)
- errorValues += "\nb: " + b;
- if (c <= 0)
- errorValues += "\nc: " + c;
- if (!errorValues.equals(""))
- {
- System.out.println("The triangle's edges can't be negative");
- System.out.println("The invalid enges are: " + errorValues);
- }
- else
- {
- if (a + b < c)
- errorValues += "\na: " + a + "\nb: " + b + "\n" + a + " + " + b + " >=! " + c;
- else if (a + c < b)
- errorValues += "\na: " + a + "\nc: " + c + "\n" + a + " + " + c + " >=! " + b;
- else if (b + c < a)
- errorValues += "\nb: " + b + "\nc: " + c + "\n" + b + " + " + c + " >=! " + a;
- if (!errorValues.equals(""))
- {
- System.out.println("The triangle inequality isn't fulfill");
- System.out.println("The invalid enges are: " + errorValues);
- }
- else
- {
- System.out.println("perimeter: " + perimeter);
- System.out.println("area: " + Math.sqrt(sqrtExpression));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement