|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
- 发信人: ioly (anguls), 信区: Java
- 标 题: Re: 请教一个问题:
- 发信站: BBS 水木清华站 (Mon May 27 01:10:58 2002)
- 因为你的输入不是'y', 而是"y\r\n"
- 所以第二次循环的时候实际是得到一个回车符
- 但是又不能不敲enter吧
- 解决办法:
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- public class A{
- public static void main(String[] s) throws IOException{
- String y = "y";
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- do{
- System.out.println("Do you want to try again?");
- }while(y.equalsIgnoreCase(reader.readLine()));
- reader.close();
- }
- };
- 【 在 sharp (一如既往) 的大作中提到: 】
- : int c = 'y';
- : while(c =='y'){
- : System.out.println("Do you want to try again?");
- : try{
- : c = System.in.read();
- : }catch(Exception e){
- : System.out.println(" Error: " + e.toString());
- : }
- : }
- : 运行时循环两次就出来了,而且第二次好像无法通过键盘输入c的值。
- : 而且,debug的时候怎么才能step into到System.in.read()函数中啊?
复制代码 |
|