一个JAVA读取字符串的问题
请大家看看下面这个程序:
import java.io.*;
class TinyEdit{
public static void main (String args[]) throws IOException{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str[]=new String[100];
System.out.print("Please enter lines of text.");
System.out.println("Enter 'stop'to quit");
for (int i=0; i<100;i++)
{
str[i]=br.readLine();
if(str[i].trim().equals("stop"))
{ break;}
}
System.out.println("\nHere is your file:");
for(int i=0;i<100;i++)
{
if(str[i].equals("stop")) break;
System.out.println(str[i]);
}
}
}
当我写了几行之后再写如STOP就发现程序不会终止了.然后我只要在str[i]=br.readLine();后写一句System.out.println(str[i]);程序运行就会变正常了,我不知道是什么原因啊,也许是那个"回车"符号的问题吧,请各位帮帮忙!