Assingment #75: Right Triangle Checker
Code
/// Name: Kiran O'Farrell
/// Program Name: Right Triangle Checker
/// File Name: Pythagorean.java
/// Date Completed: 1/29/16
import java.util.Scanner;
public class Pythagorean {
public static void main (String[] args) {
int a, b, c;
Scanner keyboard = new Scanner(System.in);
System.out.println("Type 3 integers in ascending order and I will tell you if they form a Pythagorean triplet (a right triangle).");
System.out.println("A: ");
a = keyboard.nextInt();
System.out.println("B: ");
b = keyboard.nextInt();
System.out.println("C: ");
c = keyboard.nextInt();
while (a > 0 && b > 0 && c > 0) {
if (c == Math.sqrt((a * a)+(b * b))) {
System.out.println("Yes! These three sides would form a right triangle, which means these three numbers are a Pythagorean triple.");
System.out.println("Type 3 positive integers in ascending order and I will tell you if they form a Pythagorean triplet (a right triangle).");
System.out.println("A: ");
a = keyboard.nextInt();
System.out.println("B: ");
b = keyboard.nextInt();
System.out.println("C: ");
c = keyboard.nextInt();
}
if (c != Math.sqrt((a * a) + (b * b))) {
System.out.println("No! These three sides would not form a right triangle, which means these three numbers are not a Pythagorean triple.");
System.out.println("Type 3 positive integers in ascending order and I will tell you if they form a Pythagorean triplet (a right triangle).");
System.out.println("A: ");
a = keyboard.nextInt();
System.out.println("B: ");
b = keyboard.nextInt();
System.out.println("C: ");
c = keyboard.nextInt();
}
if ((a > b) || (b > c)) {
System.out.println("Please type 3 positive integers in ascending order.");
System.out.println("Type 3 positive integers in ascending order and I will tell you if they form a Pythagorean triplet (a right triangle).");
System.out.println("A: ");
a = keyboard.nextInt();
System.out.println("B: ");
b = keyboard.nextInt();
System.out.println("C: ");
c = keyboard.nextInt();
}
} while ((a <= b) && (b <= c));
}
}
Picture of the output