本帖最后由 清心玉质 于 2013-8-19 18:20 编辑
从键盘读取数据,当输入end时结束,可是却将结束标记页作为输入的数据存储了,如果才能不存出结束标记呢?
public class TreeSetDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader bur = new BufferedReader(new InputStreamReader(System.in));
Set<String> li = new TreeSet<String>();
String line = "";
while (!line.equals(null))
{
if(line.equals("end"))
break;
try {
line = bur.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
li.add(line);
}
System.out.println(li.toString());
try {
bur.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|
|