Created
October 17, 2013 16:50
-
-
Save TheLouisHong/7028342 to your computer and use it in GitHub Desktop.
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); | |
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