Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code by Shimon Tolts
- // OpenUni Java Course
- import java.util.Scanner;
- public class Triangle {
- public static void main(String[] args) {
- Scanner scan = new Scanner (System.in);
- System.out.println ("Please enter 3 integers Triangle");
- //receiving input from the user
- int a = scan.nextInt();
- int b = scan.nextInt();
- int c = scan.nextInt();
- //performing a check if the input is valid
- if ((a >= b+c || b >= a+c || c >= a+b)) {
- System.out.print("Your input: " +a+" "+b+" "+c+" is invalid");
- } else {
- double s = (a + b +c) / 2.0;
- double d = Math.sqrt(((s-a)*(s-b)*(s-c)*s));
- //printing the result of the area of a triangle
- System.out.print("The area of a triangle is: "+ d);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement