Assignment #75
Code
/// Name: Jonathan Stine
/// Period: 5
/// Program Name: Right Triangle Checker
/// File Name: RTChecker.java
/// Date Finished: 12/9/2015
import java.util.Scanner;
public class RTChecker {
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( "A side cannot be negative. Try again doofus." );
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( "Those sides make a right triangle!" );
}
else {
System.out.println( "Nope, not a right triangle" );
}
}
}
Code Output