Advertisement
AkanthaAnil

Multidimensional Array Looping (inefficient but works)

Apr 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class MultidimensionArray {
  2.  
  3.   public static void main(String[] args) {
  4.  
  5.     int[][] multiDimensionalArray = new int[3][2];
  6.  
  7.       for (int i = 0; i < multiDimensionalArray.length; i++) {  
  8.  
  9. //i is looping through the first sub-array
  10.  
  11.          for (int j = 0; j < multiDimensionalArray[i].length; i++) {
  12.  
  13. //j loops through and finds number of elements in sub array
  14.  
  15.         System.out.print(multiDimensionalArray[i][j] + " ");
  16.  
  17. //inner loop prints the results, and when it completes, the outer loop starts again to loop over the second element in sub array
  18.  
  19.         System.out.println();
  20.  
  21. //new line
  22.       }
  23.     }
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement