/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { List<String> words = new ArrayList<>(); words.add("Kane"); words.add("Cane"); words.add("Fame"); words.add("Dame"); words.add("Lame"); words.add("Same"); marklength4(words); } public static void marklength4(List<String> themarklength){ ListIterator<String> lit = themarklength.listIterator(themarklength.size()); boolean shouldInsert = false; while(lit.hasPrevious()) { if (shouldInsert) { lit.add("****"); lit.previous(); shouldInsert = false; } shouldInsert = (n.length() == 4); } if (shouldInsert) { lit.add("****"); } } }
Standard input is empty