這是我的代碼,我有一個do-while循環,除非輸入字符串「stop」,否則它應該繼續運行。但是,當我編譯代碼時,它並沒有停下來,並陷入了無限循環。 Pease幫助。謝謝。java輸入字符串,當輸入'stop'時停止
import java.io.*;
public class input
{
public static void main(String[] argv) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "";
do
{
System.out.println("Please enter a string: ");
text = br.readLine();
System.out.println(text);
}
while (text != "stop");
}
}
更具體地說, `!=`運算符在引用類型的情況下比較引用,而對於原語則比較值(即,執行邏輯比較) – 2010-11-26 10:23:55