Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. // Code by Shimon Tolts
  2. // OpenUni Java Course
  3. import java.util.Scanner;
  4. public class Triangle {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner (System.in);
  7.         System.out.println ("Please enter 3 integers Triangle");
  8.         //receiving input from the user
  9.         int a = scan.nextInt();
  10.         int b = scan.nextInt();
  11.         int c = scan.nextInt();
  12.         //performing a check if the input is valid
  13.         if ((a >= b+c || b >= a+c || c >= a+b)) {
  14.             System.out.print("Your input: " +a+" "+b+" "+c+" is invalid");
  15.         } else {
  16.             double s = (a + b +c) / 2.0;
  17.             double d = Math.sqrt(((s-a)*(s-b)*(s-c)*s));
  18.             //printing the result of the area of a triangle
  19.             System.out.print("The area of a triangle is: "+ d);
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement