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. int mx = getTimeMatrix()[0].length;
  13. int jb = getTimeMatrix().length;
  14. ArrayList<ArrayList<Integer>> t = new ArrayList<>();
  15.  
  16. for(int i = 0; i<jb;i++){
  17. int incr = 0;
  18. t.add(new ArrayList<>());
  19. for(int j=0;j<mx;j++){
  20. if(getTimeMatrix()[i][j] != 0){
  21. t.get(i).add(incr++);
  22. }
  23. }
  24. }
  25.  
  26. System.out.println(Arrays.deepToString(t.toArray()));
  27.  
  28. }
  29.  
  30. static int[][] getTimeMatrix() {
  31. return new int[][] { { 10, 20, 0, 1 }, { 1, 0, 0, 50 }, { 1, 1, 1, 1 } };
  32. }
  33.  
  34. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
[[0, 1, 2], [0, 1], [0, 1, 2, 3]]