Program #75

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: Right Triangle Checker
    /// File Name: Triangle.java
    /// Date Finished: 1/29/2016 public class Triangle

        import java.util.Scanner;
        public class Triangle
        {
            public static void main( String[] args )
            {
                Scanner keyboard = new Scanner(System.in);
                int s1, s2, s3, ab, c;
                ab = 0; 
                c = 0;
                System.out.println( "Enter three integers: " );
                System.out.print( "Side 1: " );
                s1 = keyboard.nextInt();
                System.out.print( "Side 2: " );
                s2 = keyboard.nextInt();
                while ( s1 >= s2 )
                {
                    System.out.println( s2 + " is smaller than " + s1 + ". Try again. " );
                    System.out.print( "Side 2: " );
                    s2 = keyboard.nextInt();
                }
                System.out.print( "Side 3: " );
                s3 = keyboard.nextInt();
                while ( s2 >= s3 )
                {
                    System.out.println( s3 + " is smaller than " + s2 + ". Try again. " );
                    System.out.print( "Side 3: " );
                    s3 = keyboard.nextInt();
                }
                
                System.out.println( "Your three sides are " + s1 + " " + s2 + " " + s3 );
                ab = s1*s1 + s2*s2;
                c = s3*s3;
                if ( ab == c )
                {
                    System.out.println( "These sides *do* make a right triangle. Yippy-skippy! " );
                }
                else if ( ab != c )
                {
                    System.out.println( "NO! These sides do not make a right triangle! " );
                }
            }
        }   
    

Picture of the output

Assignment 75