高分求解决一个java问题!我就剩下40分了,都给了,呵呵。
import java.io.IOException;
class TestWhile{
public static void main(String[] args) throws IOException{
char response;
System.out.println("Are you felling better about " +
"programming?(Y or N)");
System.out.flush();
response=(char)System.in.read();
while ( response !='Y'&& response != 'N' ){
System.out.println("Invalid letter.");
System.out.println("Enter only 'Y' or 'N'");
response=(char)System.in.read();
//System.out.println("a" + response + "b");
}
if(response =='Y')
System.out.println("I am grad.");
else
System.out.println("Keep trying!");
}
}
/*
但运行结果却是这样:
Are you felling better about programming?(Y or N)
d
Invalid letter.
Enter only 'Y' or 'N'
Invalid letter.
Enter only 'Y' or 'N'
Invalid letter.
Enter only 'Y' or 'N'
Y
I am grad.
为什么在输入d时,循环了了三次呢,,请说明原因及提出修改方法
*/