Created
October 18, 2013 01:39
-
-
Save TheLouisHong/7035183 to your computer and use it in GitHub Desktop.
Once again, updated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class WhosTheBiggest { | |
public static void main(String[] args) { | |
Scanner keyboard = new Scanner(System.in); | |
mainLoop: | |
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"); | |
keyboard.next(); | |
continue; | |
} | |
int maxVal = inputs[0]; | |
for (int i : inputs) { | |
if (!isPositive(i)) { | |
System.out.println("Invalid Input: Not a Positive"); | |
continue mainLoop; | |
} | |
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