SlideServe
Menu
Préférences
© SlideServe · v2026

Multi-Dimensional Arrays in Java

birch avatar
6 diapositives · 1.2K Views · Oct 11, 2014

Multi-Dimensional Arrays in Java. "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger Dijkstra Plan for today: * multi-dimensional arrays (mostly 2D) * array creation and traversal

Multi-Dimensional Arrays in Java - slide 1
01 / 6Multi-Dimensional Arrays in Java
1 / 17

Télécharger la présentation

Multi-Dimensional Arrays in Java
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger Dijkstra Plan for today: • * multi-dimensional arrays (mostly 2D) • * array creation and traversal • * accessing rows and columns in a 2D array

  2. Array Creation When we create an array in Java, the number of pairs of square brackets indicates the dimensions of the array. So far, we’ve only used one-dimensional arrays: • int[] arr = new int[10]; • 2D array of integers: • int[][] matrix = new int[4][3]; • // 4 rows, 3 columns • 3D array of integers: • int[][][] arr2 = new int[3][5][2];

  3. 2D Arrays • int[][] matrix = new int[4][3]; • Making sense of it all: • matrix is a reference to the entire array • matrix[i][j] is for the entry in row i, column j • indexing for both rows and columns starts at 0 • matrix[0][0] is the int in the first row and first column • matrix[i] refers to row i • matrix[0] refers to the first row, or the row with index 0 • No way of referencing a column

  4. 2D Arrays • int[][] matrix = new int[3][2]; • Reasonable way to visualize 2-dimensional array • Remember: array entries are automatically initialized • arrays of numbers: entries initialized to 0 0 1 column matrix 0 1 2 row

  5. 2D Array Examples • Write a method that takes a 2D array of ints, and prints the array’s elements in row order - that is, first print the elements in row 0, then row 1, then row 2, etc. • Write a method that takes a 2D array of doubles, and returns the maximum value in the array.