Assignment #75 Right Triangle Checker
Code
/// Name: Koosha Kimelman
/// Period: 7
/// Program Name: Right Triangle Checker
/// File Name: TriangleChecker.java
/// Date Completed: 11/19/15
import java.util.Scanner;
public class TriangleChecker {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int s1, s2, s3, p1, p2, p3;
System.out.println("Enter three integers in acsending order and whole numbers only please.");
System.out.print("Side 1: ");
s1 = keyboard.nextInt();
while (s1 <= 0) {
System.out.println("It needs to be greater than 0");
System.out.print("Side 1: ");
s1 = keyboard.nextInt();
}
System.out.print("Side 2: ");
s2 = keyboard.nextInt();
while (s2 < s1) {
System.out.println("It needs to be greater than or equal to the first side.");
System.out.print("Side 2: ");
s2 = keyboard.nextInt();
}
System.out.print("Side 3: ");
s3 = keyboard.nextInt();
while (s3 < s2) {
System.out.println("It needs to be greater than or equal to the second side (although equal to will make it NOT a right triangle already).");
System.out.print("Side 3: ");
s3 = keyboard.nextInt();
}
System.out.println("\nYour three sides are " + s1 + " " + s2 + " " + s3);
p1 = (s1 * s1);
p2 = (s2 * s2);
p3 = (s3 * s3);
if (p1 + p2 == p3)
System.out.println("This makes a right triangle.");
else
System.out.println("This does not make a right triangle.");
}
}
Picture of the output