DETERMINE LARGEST,SMALLEST AND MIDDLE NUMBER IN JAVA
import java.util.Scanner;
public class NumberCheck {
public static void main(String[] args) {
int a, b, c;
String choice, s = "null";
String[] player = new String[1];
Scanner x = new Scanner(System.in);
System.out.println("Enter A to start a program");
choice = x.next();
while (choice.equals("a") || choice.equals("A") || choice.equals("r") || choice.equals("R")) {
System.out.println(" PLEASE ENTER YOUR NAME BELOW....");
player[0] = x.next();
System.out.println(" Hello.!!!" + " " + player[0]);
System.out.println();
System.out.println(
"THIS PROGRAM WILL HELP YOU TO CHECK THE LARGEST NUMBER MIDDLE NUMBER AND SMALLEST NUMBER");
System.out.println();
System.out.println("now enter your first number");
x.nextLine();
while (true)
try {
a = Integer.parseInt(x.nextLine());
break;
} catch (NumberFormatException nfe) {
System.out.println("Incorrect Input: ");
}
System.out.println("enter your second number");
while (true)
try {
b = Integer.parseInt(x.nextLine());
break;
} catch (NumberFormatException nfe) {
System.out.println("Incorrect Input: ");
}
System.out.println("enter your third number");
while (true)
try {
c = Integer.parseInt(x.nextLine());
break;
} catch (NumberFormatException nfe) {
System.out.println("Incorrect Input: ");
}
if (a > b && b > c) {
System.out.println(
"LARGEST NUMBER IS:" + a + " " + "MIDDLE NUMBER IS:" + b + " " + "SMALLEST NUMBER IS:" + c);
} else if (a > c && c > b) {
System.out.println(
"LARGEST NUMBER IS:" + a + " " + "MIDDLE NUMBER IS:" + c + " " + "SMALLEST NUMBER IS:" + b);
} else if (b > a && a > c) {
System.out.println(
"LARGEST NUMBER IS:" + b + " " + "MIDDLE NUMBER IS:" + a + " " + "SMALLEST NUMBER IS:" + c);
} else if (b > c && c > a) {
System.out.println(
"LARGEST NUMBER IS:" + b + " " + "MIDDLE NUMBER IS:" + c + " " + "SMALLEST NUMBER IS:" + a);
} else if (c > a && a > b) {
System.out.println(
"LARGEST NUMBER IS:" + c + " " + "MIDDLE NUMBER IS:" + a + " " + "SMALLEST NUMBER IS:" + b);
} else if (c > b && b > a) {
System.out.println(
"LARGEST NUMBER IS:" + c + " " + "MIDDLE NUMBER IS:" + b + " " + "SMALLEST NUMBER IS:" + a);
} else if (a > b && b == c) {
System.out.println(
"LARGEST NUMBER IS:" + a + " " + "THERE IS NO MIDDLE NUMBER" + "" + "SMALLEST NUMBER IS:" + b);
} else if (b > a && a == c) {
System.out.println(
"LARGEST NUMBER IS:" + b + " " + "THERE IS NO MIDDLE NUMBER" + "" + "SMALLEST NUMBER IS:" + a);
} else if (c > b && b == a) {
System.out.println(
"LARGEST NUMBER IS:" + c + " " + "THERE IS NO MIDDLE NUMBER" + "" + "SMALLEST NUMBER IS:" + b);
} else if (a < b && b == c) {
System.out.println(
"LARGEST NUMBER IS:" + b + " " + "THERE IS NO MIDDLE NUMBER" + "" + "SMALLEST NUMBER IS:" + a);
} else if (b < a && a == c) {
System.out.println(
"LARGEST NUMBER IS:" + a + " " + "THERE IS NO MIDDLE NUMBER" + "" + "SMALLEST NUMBER IS:" + b);
} else if (a > c && b == a) {
System.out.println(
"LARGEST NUMBER IS:" + a + " " + "THERE IS NO MIDDLE NUMBER" + "" + "SMALLEST NUMBER IS:" + c);
} else if (a == c && a == b) {
System.out.println("ALL NUMBERS ARE EQUAL");
}
System.out.println("________________________________________");
System.out.println("Enter R to run again or Q to quit");
choice = x.next();
}
System.out.println("GOOD BYE" + " " + player[0]);
}
}
No comments