public class Solution { public static void main(String[] args) throws IOException { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); //write your code here int max = Integer.MAX_VALUE; ArrayList<String> list = new ArrayList<> (); for (int x = 0; x < max; x++) { list.add(buff.readLine()); if (list.get(x).equals("end")) { list.remove("end"); break; } } for (int x = 0; x < max; x++) { System.out.println(list.get(x)); } } } INTPUT == Crusader Paladin Warrior Archer Sharpshooter Angel Demon end OUTPUT == Crusader Paladin Warrior Archer Sharpshooter Angel Demon