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