Skip to content

Instantly share code, notes, and snippets.

@TheLouisHong
Created October 17, 2013 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheLouisHong/7028342 to your computer and use it in GitHub Desktop.
Save TheLouisHong/7028342 to your computer and use it in GitHub Desktop.
Updated
import java.util.Scanner;
public class WhosTheBiggest {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
while (true) {
Integer[] inputs = new Integer[3];
System.out.println("Enter 3 positive digits");
try {
inputs[0] = keyboard.nextInt();
inputs[1] = keyboard.nextInt();
inputs[2] = keyboard.nextInt();
} catch (Exception e) {
System.out.println("Invalid Input: Not an Integer");
continue;
}
int maxVal = inputs[0];
for (int i : inputs) {
if (!isPositive(i)) {
System.out.println("Invalid Input: Not a Positive");
break;
}
if (i>maxVal)
maxVal = i;
}
System.out.println("The largest value is: " + maxVal);
System.out.println("Done");
System.out.println();
}
}
public static boolean isPositive(int input) {
return input >= 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment