
Slides8.1_2DArrays
Presentation
•
Computers
•
11th Grade
•
Practice Problem
•
Medium
Lauren Wheelwright
Used 1+ times
FREE Resource
23 Slides • 5 Questions
1
2
1D Arrays - Review
String[] arr1 = new String[6];
0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
null | null | null | null | null | null |
boolean[] arr2 = new boolean[2];
i=0 | i=1 |
|---|---|
false | false |
3
1D Arrays - Review
String[] arr1 = new String[6];
arr1[2] = "yay!";
0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
null | null | "yay!" | null | null | null |
boolean[] arr2 = new boolean[2];
arr2[arr2.length - 1] = true;
i=0 | i=1 |
|---|---|
false | true |
4
2D Arrays
String[][] arr1 = new String[3][5];
null | null | null | null | null |
|---|---|---|---|---|
null | null | null | null | null |
null | null | null | null | null |
5
2D Arrays
String[][] arr1 = new String[3][5];
null | null | null | null | null |
|---|---|---|---|---|
null | null | null | null | null |
null | null | null | null | null |
# Rows
{
6
2D Arrays
String[][] arr1 = new String[3][5];
null | null | null | null | null |
|---|---|---|---|---|
null | null | null | null | null |
null | null | null | null | null |
# Rows
{
# Columns
7
2D Arrays
String[][] arr1 = new String[3][5];
null | null | null | null | null |
|---|---|---|---|---|
null | null | null | null | null |
null | null | null | null | null |
# Rows
{
# Columns
Type stored
8
Multiple Choice
What is the proper syntax to initialize a 6x6 2D String array?
String[] array = new String[6][6];
int[][] array = new int[6][6];
String[][] array = new String[6];
String[][] array = new String[6][6];
9
Initialize arrays with no default values
int[] arr = {5,8,9,4};
i=0 | i=1 | i=2 | i=3 |
|---|---|---|---|
5 | 8 | 9 | 4 |
10
Initialize arrays with no default values
int[][] arr = {
{3,4,5},
{6,7,8},
{9,0,1}
};
int[] arr = {5,8,9,4};
i=0 | i=1 | i=2 | i=3 |
|---|---|---|---|
5 | 8 | 9 | 4 |
3 | 4 | 5 |
|---|---|---|
6 | 7 | 8 |
9 | 0 | 1 |
11
Initialize arrays with no default values
int[][] arr = {
{3,4,5},
{6,7,8},
{9,0,1}
};
int[] arr = {5,8,9,4};
i=0 | i=1 | i=2 | i=3 |
|---|---|---|---|
5 | 8 | 9 | 4 |
3 | 4 | 5 |
|---|---|---|
6 | 7 | 8 |
9 | 0 | 1 |
int arr[][] = {
{4,3},
{1,8},
{7,9}
};
4 | 3 |
|---|---|
1 | 8 |
7 | 9 |
I know this looks made up, but it's legit!
12
Multiple Choice
Which of these would cause a compilation error?
String[][] w = new int[4][3];
boolean[][] y = {{true,false}, {false, true}};
int z[][] = {{3,4}, {5,6}, {7,8}};
int[][] x = new int[0][0];
13
Indexing into a 2D array
int[][] x = new int[4][3];
// Print # rows
System.out.println(_________);
// Print # columns
System.out.println(_________);
type[][] name = new type[rows][cols];
0 | 0 | 0 |
|---|---|---|
0 | 0 | 0 |
0 | 0 | 0 |
0 | 0 | 0 |
14
Indexing into a 2D array
int[][] x = new int[4][3];
// Print # rows
System.out.println(x.length);
// Print # columns
System.out.println(_________);
type[][] name = new type[rows][cols];
0 | 0 | 0 |
|---|---|---|
0 | 0 | 0 |
0 | 0 | 0 |
0 | 0 | 0 |
15
Indexing into a 2D array
int[][] x = new int[4][3];
// Print # rows
System.out.println(x.length);
// Print # columns
System.out.println(x[0].length);
type[][] name = new type[rows][cols];
0 | 0 | 0 |
|---|---|---|
0 | 0 | 0 |
0 | 0 | 0 |
0 | 0 | 0 |
16
Multiple Choice
int[][] grid = new int[5][3]
What is the value of grid.length?
0
5
3
15
17
Multiple Choice
int[][] grid = new int[5][3]
What is the value of grid[0].length?
0
5
3
15
18
Predict...
int[][] x = {
{9,8,7},
{6,5,4},
{3,2,1},
{0, -1, -2}
};
System.out.println(x[2][1]);
9 | 8 | 7 |
|---|---|---|
6 | 5 | 4 |
3 | 2 | 1 |
0 | -1 | -2 |
19
Predict...
int[][] x = {
{9,8,7},
{6,5,4},
{3,2,1},
{0, -1, -2}
};
System.out.println(x[2][1]);
9 | 8 | 7 |
|---|---|---|
6 | 5 | 4 |
3 | 2 | 1 |
0 | -1 | -2 |
20
Predict...
int[][] x = {
{9,8,7},
{6,5,4},
{3,2,1},
{0, -1, -2}
};
System.out.println(x[2][1]);
// Prints 2
9 | 8 | 7 |
|---|---|---|
6 | 5 | 4 |
3 | 2 | 1 |
0 | -1 | -2 |
21
Multiple Choice
A 2D array is initialized:
int [][] array = {{1,2,3},{4,5,6},{7,8,9}};
What is the result of array[0][1] + array[2][0]?
10
15
9
5
22
Project 8.1 - 8.1.5 Manipulating 2D Arrays
The updateValue method changes the value in arr at [row][col] to value
Call updateValue 3 times
public static void updateValue(int[][] arr, int row, int col, int value)
Set last value of first array to the length of the entire 2D array.
Set last value of 2nd array to the total number of values in the entire 2D array.
Set last value of 3rd array to the sum of the 1st value in 2D array and last value in 2D array.
updateValue(myArray, 1, myArray[0].length-1, 12);
The line above sets the last value of the 2nd array to 12
23
Project 8.1 - 8.1.6 Complete Chessboard
TODO
Initialize an 8x8 2D String array
Add all chess pieces to the board!
chess[0][0] = "Rook"; // sets the top left square to "Rook"
24
25
26
27
28
Show answer
Auto Play
Slide 1 / 28
SLIDE
Similar Resources on Wayground
23 questions
Work and Power
Presentation
•
10th Grade
25 questions
Semafori standard Posix1.b
Presentation
•
11th Grade
20 questions
Changing Percents to Decimals
Presentation
•
KG
18 questions
Evolución de la web
Presentation
•
10th Grade
24 questions
WRITING A RESUME
Presentation
•
11th Grade
20 questions
Slope Intercept Form
Presentation
•
12th Grade
21 questions
Moles and Molar Mass
Presentation
•
10th Grade
23 questions
Valence Electrons, Lewis Dot Diagrams and Ions
Presentation
•
10th - 12th Grade
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade