fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. try(Scanner stdin = new Scanner(System.in))
  13. {
  14. int numberofsquares=1;
  15. int prgrm=0;
  16. int v=1;
  17. List<List<String>> square = new ArrayList<>();
  18. while(prgrm==0)
  19. {
  20. System.out.println("Enter another square? (y/n)");
  21. if (stdin.next().startsWith("y"))
  22. {
  23. for(int i=0; i<3; i++)
  24. {
  25. square.add(new ArrayList<String>());
  26. //Get last element's index
  27. int lastIndex = square.size()-1;
  28. //Get last element and add a String
  29. square.get(lastIndex).add((i+1) +","+v+","+stdin.next());
  30. v++;
  31. }
  32. }
  33. else
  34. {
  35. prgrm++;
  36. }
  37. }
  38. if (prgrm==1)
  39. {
  40. System.out.println("Finish");
  41. }
  42. System.out.println("Lists are: " + square);
  43. }
  44. }
  45. }
Success #stdin #stdout 0.12s 29120KB
stdin
y 2 1 3
y 5 111 65
n
stdout
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]]