Assignemnt #75 Right Triangle Checker
Code
Name: Iaroslav Titov
Period: 7
Project Name: RiTri
File Name: RiTri.java
Date: 1/11/2015
import java.util.Scanner;
import java.util.InputMismatchException;
public class RiTri
{
public static void main( String[] args ) throws Exception
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter three sides of a triangle in ascending order.");
int[] sides = new int[3];
int counter = 0;
boolean order = true;
do
{
try
{
System.out.print("Enter side "+(counter+1)+":");
sides[counter] = keyboard.nextInt();
}
catch (InputMismatchException e)
{
System.out.println("WRONG INPUT!!!");
}
if (counter!=0) order = (sides[counter-1] < sides[counter]);
if (order) counter++;
else System.out.println("Its not in ascending order, try again!");
}
while (counter < 3);
order = (sides[2]*sides[2] == (sides[0]*sides[0]) + (sides[1]*sides[1]));
System.out.println();
System.out.println("The three sides are : "+sides[0]+" "+sides[1]+" "+sides[2]);
System.out.println();
if (order) System.out.println("They do make up a right trianlge.");
else System.out.println("They don't make up a right triangle");
}
}
Picture of the output