Assignment #75
Code
///Name: Cody Swain
///Period: 6
///Project Name: RightTriangle
///File Name: RightTriangle.java
///Date: 1/8/16
import java.util.Scanner;
public class RightTriangle
{
public static void main( String[] args)
{
Scanner keyboard = new Scanner(System.in);
int side1, side2, side3;
System.out.println( "Enter three integers: " );
System.out.println();
System.out.print( "Side 1: " );
side1 = keyboard.nextInt();
System.out.print( "Side 2: ");
do{
side2 = keyboard.nextInt();
if ( side2 < side1 ){
System.out.println( side2 + " is smaller than " + side1 + ". Try again. " );
System.out.print( "Side 2: ");
side2 = keyboard.nextInt();
}
}while ( side2 < side1 );
System.out.print( "Side 3: ");
do{
side3 = keyboard.nextInt();
if ( side3 < side2 ){
System.out.println( side3 + " is smaller than " + side3 + ". Try again. " );
System.out.print( "Side 3: ");
side3 = keyboard.nextInt();
}
}while ( side3 < side2 );
System.out.println( "Your three sides are " + side1 + " " + side2 + " " + side3 );
if ( (side3*side3) == (side1*side1) + (side2*side2) ){
System.out.println( "These sides make a right triangle! ");
}
else {
System.out.println( "These sides do not make a right triangle" );
}
}
}
Picture of the output