Assignemnt #75: Right Triangle Checker
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: RightTriangleChecker
/// File Name: RightTriangleChecker.java
/// Date Finished: 12/15/2015
import java.util.Scanner;
public class RightTriangleChecker
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner (System.in);
int side1, side2, side3;
double a, b, c, d;
System.out.println("Enter 3 integers for the sides of a right triangle!");
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 + ". Please 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 + ". Please try again.");
System.out.print("Side 3: ");
side3 = keyboard.nextInt();
}
while (side3 < side1)
{
System.out.println(side3 + " is smaller than " + side1 + ". Please try again.");
System.out.print("Side 3: ");
side3 = keyboard.nextInt();
}
System.out.println("Your three sides are " + side1 + ", " + side2 + ", and " + side3 + ".");
a = Math.pow(side1, 2);
b = Math.pow(side2, 2);
c = Math.pow(side3, 2);
d = a + b;
if ( d == c )
System.out.println("These sides DO(ot) make a right triangle! Congratulations!");
if ( d != c )
System.out.println("Nawww dawg you can't make a right triangle wit dese sides!");
}
}
Picture of the output