Skip to main content

Multidimensional Arrays

int[][] a = new int[3][4];
1

Array Traversal

int[][] data = {
    { 1, 2, 3 },
    { 4, 5 },
    { 6, 7, 8, 9 }
};

for (int i = 0; i < data.length; i++) {
    for (int j = 0; j < data[i].length; j++) {
        System.out.print(data[i][j] + "\t");
    }
    System.out.println();
}

Exercise

Exercise 1

  • Create an array that can hold nn integers
  • Fill up the array with user inputs
  • Ask the user to enter a value that they want to find
  • Show if the value is in the array
1

Exercise 2

  • Create an array that can hold nn integers
  • Fill up the array with user inputs
  • Ask the user to enter a value that they want to find
  • Show how many times the value appears in the array
2

Exercise 3

  • Create an array that can hold nn integers
  • Fill up the array with user inputs
  • Ask the user to enter a value that they want to find
  • Show whether the value is in the array or not
3

Exercise 4

  • Create an array that can hold nn integers
  • Fill up the array with user inputs
  • Ask the user to enter a value that they want to find
  • Show on which index the value appears in the array
4

Exercise 5

  • Create an array that can hold nn integers
  • Fill up the array with user inputs
  • Find the largest value in the array
  • Also display on which index the maximum value appears in the array
5

Exercise 6

  • Create a 2-dimensional array that can hold m x n integers
  • Fill up the array with user inputs
  • Display the contents of the array
6

Exercise 7

  • Create a 2-dimensional array that can hold m x n integers
  • Fill up the array with user inputs
  • Ask the user to enter a value that they want to find
  • Show how many times the value appears in the array
7

Exercise 8

  • Create a 2-dimensional array that can hold m x n integers
  • Fill up the array with user inputs
  • Find the largest value in the array
  • Also display on which index the maximum value appears in the array
8