package io;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class SystemIndemo {
public static void main(String[] args) throws Exception{
InputStream in = System.in;
InputStreamReader reader = new InputStreamReader(in);
BufferedReader br = new BufferedReader(reader);
String str = null;
while(str!="z"){
str = br.readLine();
System.out.println("Input :"+str);
}
System.out.println("The end.");
br.close();
}
}
為什麼輸入z回車之後while循環不會退出呢?
String str = "";
while(!"z".equals(str) && str != null){
str = br.readLine();
System.out.println("Input :"+str);
}
這樣寫比較保險報吧。