Created
January 23, 2018 21:21
-
-
Save yukeehan/aba339f4f49b2b66a03305eaa32cacaf to your computer and use it in GitHub Desktop.
do-while loop to discard any unwanted character remaining in the input buffer
This file contains hidden or 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 chapter3; | |
public class TryThis3_2 { | |
public static void main(String args[]) | |
throws java.io.IOException{ | |
char choice,ignore; | |
do { | |
System.out.println("1.if 2.switch 3.for 4.while 5.do-while\nchooose one"); | |
choice = (char)System.in.read(); | |
do { | |
ignore = (char)System.in.read(); | |
}while(ignore != '\n'); | |
}while(choice<'1'|choice>'5'); | |
System.out.println("\n"); | |
switch(choice) { | |
case'1': System.out.println("if blablabal"); break; | |
case'2': System.out.println("switch blabal"); break; | |
case'3': System.out.println("for balbal"); break; | |
case'4': System.out.println("while balbal"); break; | |
case'5': System.out.println("do-while blabla"); break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment