Last active
May 8, 2019 09:57
-
-
Save SakshamInABox/a8a40b9069685dd7c6b06feff0cdc284 to your computer and use it in GitHub Desktop.
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
package testinggrounds; | |
import java.util.InputMismatchException; | |
import java.util.Scanner; | |
public class TestingGrounds { | |
public static void main(String[] args) { | |
boolean mismatch; | |
do { | |
mismatch = false; | |
try { | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Please Enter A Number: "); | |
int userInput = scanner.nextInt(); | |
while (userInput < 0) { | |
System.out.print("Sorry Number Needs To Be Postivie. Please Try Again: "); | |
userInput = scanner.nextInt(); | |
} | |
} catch (InputMismatchException e) { | |
mismatch = true; | |
System.out.println("Sorry The Input Needs To Be A Number. Please Try Again."); | |
} | |
} while(mismatch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment