import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/*
* 循环接收用户从键盘输入多个字符串知道输入“end”时循环结束,并将接收的字符倒叙打印。
*/
public class Test01 {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串,以“end”结束");
while (true) {
String s = sc.nextLine();
if (s.equals("end")) {
break;
} else {
list.add(s);
System.out.println("请输入字符串,以“end”结束");
}
}
// Collections.sort(list);
Collections.reverse(list);
System.out.println(list);
}
}
|
|