Assignment #75 and Right Triangle Checker
Code
/// Name: Brendan Baird
/// Period: 6
/// Program Name: Right Triangle Checker
/// File Name: RightTriCheck.java
/// Date Finished: 11/30/2015
import java.util.Scanner;
public class RightTriCheck
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int side1, side2, side3;
System.out.println("Enter three integers:");
do
{
System.out.print("Side 1: ");
side1 = keyboard.nextInt();
if (side1 <= 0)
System.out.println(side1 + " is not greater than 0. Try again.");
} while (side1 <= 0);
do
{
System.out.print("Side 2: ");
side2 = keyboard.nextInt();
if (side2 < side1)
System.out.println(side2 + " is smaller than " + side1 + ". Try again.");
} while (side2 <= side1);
do
{
System.out.print("Side 3: ");
side3 = keyboard.nextInt();
if (side3 < side2)
System.out.println(side3 + " is smaller than " + side2 + ". Try again.");
} while (side3 <= side2);
System.out.println();
System.out.println("Your three sides are " + side1 + " " + side2 + " " + side3 + ".");
if ( side3 == Math.sqrt(side1*side1 + side2*side2) )
System.out.println("These sides *do* make a right triangle!");
else
System.out.println("NO! These sides do not make a right triangle!");
}
}
Picture of the output