java 2D arrays

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/8

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

9 Terms

1
New cards

Two Dimensional Arrays

A collection of data that is stored in a table or grid, with rows and columns.

2
New cards

Rows

Horizontal

3
New cards

Columns

Vertical

4
New cards

declaration statement

datatype[][] nameOfArray = new dataType[][];

int[][] myTable = new int [4][7];

5
New cards

remember

  • first spot starts at 0

  • go down first, then to the side

  • when declaring, it counts normally

  • when choosing a spot, start from 0

6
New cards

grid.length

the number of rows

7
New cards

grid [0].length

number of columns

8
New cards

Traversing

for (int r = 0; r < myTable.length; r++ )

{

  for (int c = 0; c < myTable[0].length; c++)

   {

system.out.println(myTable[r][c]);

   }

}

9
New cards

Populating with an initializer list

int [][] grid = {  { 5, 2, 12, -4, 95} ,        //row 0

                   { 33, 59, 23, 68, 200},      //row 1

                   { 42, 87, -99, 312, 0}  } ;  //row 2