问个弱智 System.in.read()问题
System.in.read()是一个类似c语言中getchar()的函数?
我执行如下代码,当我输入11时会执行两遍函数,441会执行三次。有高手解释下这个走好几次的原因?顺便介绍下System.in.read()的用法,我还想获取int 11,是不是的换个函数
[code=Java][/code]
public class Help {
public static void main( String args[] )
throws
java.io.IOException {
char choice;
for (;;)
{
do
{
System.out.println("Please ");
System.out.println("1. if ");
System.out.println("2.while ");
System.out.println("3.for ");
System.out.println("4.break ");
System.out.println("5.continue ");
do
{
choice = (char)System.in.read();
}
while ( choice =='\n' | choice == '\r');
}
while ( choice <'1' | choice > '3' & choice != 'q');
if (choice == 'q') break;
System.out.println();
switch(choice)
{
case '1': System.out.println(" ififififi");
break;
case '2': System.out.println(" whilewhile");
break;
case '3': System.out.println(" forforforf");
break;
}
System.out.println();
}
}
}
------解决方案--------------------
解决了就给分把……