public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); ArrayList <String> list = new ArrayList<>(); for(;;) { String a = reader.readLine(); if(a.equals("结束")) // a = " 结束 " why can't ? { break;} list.add(a); } for( String ohh : list) { System.out.println(ohh); } //在此编写你的代码 } }