Last active
December 20, 2015 12:58
-
-
Save dhust/6134689 to your computer and use it in GitHub Desktop.
IO - validation
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
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
int number = 0; | |
Scanner extraction; | |
while (number < 1 || number > 10) { | |
System.out.print("Enter a number (1-10): "); | |
String line = input.nextLine(); | |
extraction = new Scanner(line); | |
if (extraction.hasNextInt()) { | |
number = extraction.nextInt(); | |
} | |
} | |
System.out.println("Your number was: " + number); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment