java 输入字符串 为什么输入了两次就停止了(不是exits字符串)

public class T {
public static void main(String[] args){
try{
String str=null;
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
str=bf.readLine();
if(!str.equalsIgnoreCase("exits")){
str=bf.readLine();
}
}catch(Exception e){
e.printStackTrace();
}
}
}

你的代码不在一个循环中,所以一直顺序执行。

[code="java"]

// 读取第一次输入
str=bf.readLine();
if(!str.equalsIgnoreCase("exits")){
// 如果第一次输入不为exits,则读取第2次输入
str=bf.readLine();
}

//然后就接着往下执行,就退出程序了!
[/code]

你应该将读取输入的这部分,放在一个循环中!

public class InputString {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
        String str = null;
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        while(bf.readLine()!= null){
            System.out.println("   bf.readLine():"+bf.readLine());
            if(!bf.readLine().equalsIgnoreCase("exits"))
                str = bf.readLine();
            else 
                break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

好好看一下,你也就明白了。。。