Download presentation
Presentation is loading. Please wait.
Published byPhoebe Perkins Modified over 8 years ago
1
ARRAY AND LOOPS REVIEW Mr. Crone
2
What will the code below print? int[] arry = {2, 5, 2, 1, 3}; for(int i = 0; i < 5; i ++) System.out.print(arry[i]);
3
int[] arry = {2, 5, 2, 1, 3}; for(int i = 0; i < 5; i ++) System.out.print(arry[i]); // prints: 25213
4
Does the code below alter Array arry? int[] arry = {3,1, 3, 4}; for(int i = 0; i < 4; i ++) arry[i] / 2;
5
Does the code below alter Array arry? int[] arry = {3,1, 3, 4}; for(int i = 0; i < 4; i ++) arry[i] / 2; // Does nothing! // Should be: arry[i] = arry[i] / 2
6
//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}}; System.out.println(arry.length);
7
//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}}; System.out.println(arry.length); // 2
8
//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}, {"Roy", "Nascar", "Basketball", "River"}}; System.out.println(arry[2].length);
9
//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}, {"Roy", "Nascar", "Basketball", "River"}}; System.out.println(arry[2].length); // 4
10
What does the code below do/print? int[] arry = {2, 5, 2, 1, 3}; int min = arry[0]; for(int i = 1; i < 5; i ++){ if(arry[i] < min) min = arry[i]; } System.out.println(min);
11
What does the code below do/print? int[] arry = {2, 5, 2, 1, 3}; int min = arry[0]; // Initialized min to first element for(int i = 1; i < 5; i ++){ if(arry[i] < min) // Checks each element’s size min = arry[i]; //Keeps track of smallest num. } System.out.println(min);
12
What are parallel arrays?
13
// Parallel arrays are multiple arrays in which corresponding elements are related.
14
Instantiate a one-dimensional array with an initializer list.
15
int[] arry = {1, 2, 3, 4, 5};
16
What happens when a program attempts to access an item at an index that is less than zero or greater than or equal to the array’s length? Name the type of error.
17
//ArrayIndexOutofBoundsException.
18
What will the code below print? int[] arry = {34, 23, 67, 89, 12}; System.out.print( a[a.length - 1] );
19
What will the code below print? int[] arry = {34, 23, 67, 89, 12}; System.out.print( a[a.length - 1] ); // a[4] // 12
20
What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[1] + 5);
21
What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[1] + 5); // 10
22
What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[arry[0]]);
23
What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[arry[0]]); // 1
24
What does the code below print: int[] arry = {2, 5, 3, 6}; System.out.print(arry[arry[2]] * 2);
25
What does the code below print: int[] arry = {2, 5, 3, 6}; System.out.print(arry[arry[2]] * 2); // 12
26
True or False The for-loop below will access every element in the array arry. int[] arry = {2, 5, 3, 2, 1}; for(int i = 1; i <= 5; i ++){ arry[i] = arry[i] + 1; }
27
True or False The for-loop below will access every element in the array arry. int[] arry = {2, 5, 3, 2, 1}; for(int i = 1; i <= 5; i ++){ arry[i] = arry[i] + 1; } // False
28
Declare and instantiate a two dimensional Integer array called table that has 5 rows and 6 elements in each row.
29
Declare and instantiate a two dimensional int array called table that has 5 rows and 6 elements in each row. // int[][] table = new int[5][6];
30
What is the difference between the physical size and logical size of an array?
31
//Physical is the actual size of the array. Logical is how many elements are currently being used.
32
What is a ragged array?
33
// A two dimensional array that has different number of elements in each row.
34
Final Question! What will the code below print? String[][] arry = {{“hi”, “Mine”, “boo”}, {“zoo”, “food”, “dog”}}; int sum = 0; for(int i = 1; i < 3; i ++) sum += arry[0][i].length(); System.out.print(sum + arry.length);
35
Final Question! What will the code below print? String[][] arry = {{“hi”, “Mine”, “boo”}, {“zoo”, “food”, “dog”}}; int sum = 0; for(int i = 1; i < 3; i ++) sum += arry[0][i].length(); // sum = 7 System.out.print(sum + arry.length); // 7 + 2 = 9!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.