Given an ArrayList called nums...
for (int i = 0; i <= 50; i++){
if i%2==0{
nums.add(i);}}
What is append even numbers between 0 and 50 to nums?
The first letter of a string named str.
What is str.substring(0,1)?
In a method to find the maximum value in an array called "incomes", we initialize the variable holding the maximum to this value...
What is prices[0]?
(or the first element in prices)
What data type do ArrayLists require?
(Which is a reason why wrapper classes and autoboxing are needed)
What are objects of a class?
What is the index of the bottom right element in a 4 x 8 array?
What is [3][7]?
(coordinates ok)
public int getWhat(){
int x = values[0];
for(int item : values){
if (item > x){
x = item;}}
return x;}
What is return the maximum number in an array called values?
The last letter of String str with length = k
What is str.substring(k-1, k)
or str.substring(k-1)
Write a "for i" loop condition to traverse the elements in an array of Strings called nbaTeams.
You must be completely accurate
for (int i = 0; i<nbaTeams.length; i++)
Write a "for i" loop condition to traverse the elements in an ArrayList of Strings called nbaTeams, in REVERSE.
You must be completely accurate.
for (int i = nbaTeams.size() - 1; i >=0; i-- )
Write a "for i" loop condition to traverse the elements in an array of Strings called nbaTeams.
You must be completely accurate
Declare and initialize an array called "letters" with these values:
a b c
d e f
What is String letters = {{a,b,c}, {d,e,f}};
Given an array of integers called values
public int mystery(int x){
int y = 0;
for(int item : values){
if (item == x){
y++;
}} return y; }
What is count how many times x appears in values?
Inside a "for i loop", the character at index i in String str.
What is str.substring(i, i + 1)?
Write an enhanced for loop condition to traverse an array of Animal objects called zoo. (zoo is the array name)
for (Animal beast: zoo)
(local variable name "beast" can vary
While traversing an Arraylist using the condition for (Student warrior : roster), write a condition to check if the current element has the name "Jair"
What is... if (warrior.getName().equals("Jair"))?
Declare a 10 x 5 array of doubles called "prices"
What is double[][] prices = new double[10][5];
Given an ArrayList mystery, int number:
while (number >0){
mystery.add(0, number%10);
number = number/10;
}
What is parse a number into its digits?
The substring BEFORE a character at index k in String str
What is str.substring(0, k)?
An enhanced for loop can traverse an array from beginning to end and access its elements. State what it CANNOT do.
What is modify the array or do anything but go from beginning to end? (answers may vary)
Write a single command that would declare and initialize an ArrayList of Integers called "ages" (you don't need to populate it).
What is ArrayList<Integer> ages = new ArrayList<Integer>();
Write the conditions for a nested enhanced for loop to traverse a 2D array of integers called stuff. You can leave out curly brackets.
for (int[] row: stuff )
for(int column : row)
(local variable names may vary)
Given Strings a,b
int k = indexOf(b); and int x = b.length();
"a.substring(0, k) + a.substring(k+x)" would ...
What is remove the first instance of string b from the string a?
A substring of str with a length of x, located at index i
What is str.substring(i, i + x)?
Write a command to access the name of a Student object at index i, in an array called roster.
(Assume conventional getter names.)
What is roster[i].getName() ?
Write a command that would set the name of an Animal at index 5 in an arrayList called pets to "Captain".
What is pets.get(5).setName("Captain");
Write the conditions for a nested "for i" loop to traverse a 2D array called stuff. You can leave out curly brackets.
for(int r = 0; r < stuff.length; r++)
for(int c = 0; c < stuff[0].length; c++)