编写程序循环接收用户从键盘输入多个字符串直到输入end时循环结束并将所有已输入的字符串按字典顺序倒序打印
public static void main(String[] args) throws IOException {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String line;
StringBuffer s=new StringBuffer();
while((line=in.readLine())!=null)
{
if(line.equals("end"))
break;
TreeSet<String> set=new TreeSet<String>();
set.add(line);
Iterator<String>it =set.iterator();
{
String r=it.next();
s.append(r);
}
}
System.out.print(s.reverse());
} |
|