/* 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 { { { int numberofsquares=1; int prgrm=0; int v=1; List<List<String>> square = new ArrayList<>(); while(prgrm==0) { if (stdin.next().startsWith("y")) { for(int i=0; i<3; i++) { square.add(new ArrayList<String>()); //Get last element's index int lastIndex = square.size()-1; //Get last element and add a String square.get(lastIndex).add((i+1) +","+v+","+stdin.next()); v++; } } else { prgrm++; } } if (prgrm==1) { } } } }
y 2 1 3 y 5 111 65 n
Enter another square? (y/n) Enter another square? (y/n) Enter another square? (y/n) Finish Lists are: [[1,1,2], [2,2,1], [3,3,3], [1,4,5], [2,5,111], [3,6,65]]