Right Angles
import java.util.Scanner;
public class rig
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int side1, side2, side3;
System.out.println( "Enter three integers:" );
System.out.print( "Side 1: " );
side1 = keyboard.nextInt();
while ( side1 <= 0 )
{
System.out.println( "Come on, a side can't be negative." );
System.out.print( "Side 1: " );
side1 = keyboard.nextInt();
}
System.out.print( "Side 2: " );
side2 = keyboard.nextInt();
while ( side2 < side1 )
{
System.out.println( side2 + " is smaller than " + side1 + ", try again." );
System.out.print( "Side 2: " );
side2 = keyboard.nextInt();
}
System.out.print( "Side 3: " );
side3 = keyboard.nextInt();
while ( side3 < side2 )
{
System.out.println( side3 + " is smaller than " + side2 + ", try again." );
System.out.print( "Side 3: " );
side3 = keyboard.nextInt();
}
System.out.println( "Your three sides are " + side1 + ", " + side2 + ", and " + side3 + "." );
double right = Math.sqrt( side1 * side1 + side2 * side2 );
if ( right == side3 )
{
System.out.println( "Yup, those sides make a right triangle!" );
}
else
{
System.out.println( "Not a right triangle! Sorry" );
}
}
}
Picture of the output