Assignemnt #75 and TriangleChecker
Code
/// name: Leila Ordukhani
/// period: 6
/// program name: Sixty-Fifth Program
/// file name: TriangleChecker.java
/// date finished: 1/6/16
import java.util.Scanner;
public class TriangleChecker
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int x, y, z;
System.out.println("Enter three integers:");
do
{
System.out.print("Side 1: ");
x = keyboard.nextInt();
if (x <= 0)
System.out.println(x + " is not greater than 0. Try again.");
} while (x <= 0);
do
{
System.out.print("Side 2: ");
y = keyboard.nextInt();
if (y < x)
System.out.println(y + " is smaller than " + x + ". Try again.");
} while (y <= x);
do
{
System.out.print("Side 3: ");
z = keyboard.nextInt();
if (z < y)
System.out.println(z + " is smaller than " + y + ". Try again.");
} while (z <= y);
System.out.println();
System.out.println("Your three sides are " + x + " " + y + " " + z + ".");
if ( z == Math.sqrt(x*x + y*y) )
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