Unit 3 Exam Flashcards
(15 cards)
Min number of iterations for do while
1
Min number of iterations for while
0, because boolean expression is first so if it is false loop never runs
What happens with continue inside a for
Skips the code below it and increments
Min number of iterations for for
1
What does empty boolean expression in for do
Always evaluates to true
for(;;){
SOP(“hello”)
}
Infinite loop
Reference of array
Address where data is stored in RAM
Index of array
Integer between 0 and array size - 1
int [] nums = new int [10]
int = data type
[ ] = array
nums = array name
new = reserves enough RAM to store size values
10 = size
nums [1] = 3;
nums [3] = 20;
nums [7] = nums [nums [1]] - 8;
nums [7] is 12
.length
Constant that is equal to the size of the array
Used for iterating through an array
Initializing arrays
int [] nums = new int [50]; // all values set to 0
String [] days = {“Mon”, “Tues”, “Wed”};
Passing arrays to methods
When an array is passed using a method, the reference is passed by value
This means that when an array that is passed through a method is modified, it is changing the original
2d arrays
Each element in the array is also an array
Syntax int [ ] [ ] arr
Iterating through a 2d array
for(int row = 0; row < a.length; row++){
for(int col = 0; col < a[row].length; col++){
System.out.print(a[row][col] + “ “);
} // for
System.out.println(“ “);
} // for