Advertisement
therrontelford

Perimeter of triangle

Nov 12th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Chap3_19PerimeterOfTriangle {
  3.  
  4.     public static void main(String[] args) {
  5.         Scanner kb = new Scanner(System.in);
  6.         System.out.println("Enter the 3 segment lengths");
  7.  
  8.         // get user input
  9.         int a = kb.nextInt();
  10.         int b = kb.nextInt();
  11.         int c = kb.nextInt();
  12.        
  13.         // sum of any two sides must be greater than the 3rd side
  14.         if ((a+b)<= c || (a+c)<= b || (b+c)<=a)
  15.             System.out.println("this could not form a triangle");
  16.         else
  17.             System.out.println("The perimeter is "+ (a+b+c));
  18.  
  19.     }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement