Assignemnt #75 and Right Triangle Checker
Code
/// Name: David Shkolnikov
/// Period: 6
/// Program Name: Right Triangle Checker
/// File Name: RightTriangleChecker.java
/// Date Finished: 1/26/2016
import java.util.Scanner;
public class RightTriangleChecker
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int s1, s2, s3;
System.out.println("Enter three integers:");
System.out.print("Side 1: ");
s1 = keyboard.nextInt();
do
{
System.out.print("Side 2: ");
s2 = keyboard.nextInt();
if (s2 < s1)
System.out.println(s2 + " is smaller than " + s1 + ". Try again.");
}
while (s2 < s1 );
do
{
System.out.print("Side 3: ");
s3 = keyboard.nextInt();
if ( s3 < s2 )
{
System.out.println(s3 + " is smaller than " + s2 + ". Try again.");
}
}
while ( s3 < s2 );
System.out.println("\nYour three sides are " + s1 + " " + s2 + " " + s3 );
int sides = (s1 * s1) + (s2 * s2);
if ( Math.sqrt(sides) == s3 )
System.out.println("These sides *do* make a right triangle. Good for you!");
else
System.out.println("No! These sides do not make a right triangle!");
}
}
Picture of the output