What is a 2D array?
A 2D array, also known as a matrix, is an array of arrays. It can be thought of as a grid or table with rows and columns, where each cell holds an element of the same data type.
What is a WHILE statement?
A WHILE statement executes code x number of times until a certain condition is met.
Ex: while (wishes < 3) {
wishes++;
}
What is an if statement?
Executes a block of code when a specified boolean expression is evaluated as true.
What is the purpose of string methods and what is an example how to write one?
The purpose of string methods is so programmers are allowed to share words through code and not just instructions of how to do something.
String str = "Correct!";
Can Booleans only be True or false?
Yes
How do you declare a 2D array in Java?
int[][] matrix = new int[3][4]; // A 2D array with 3 rows and 4 columns
What is an increment?
When a counter/iterator is used and you can add an increment that increases or decreases the value. You can use a for loop for this.
Ex: // counter
int wishes = 0;
while (wishes < 3) {
System.out.println("Wish granted.");
//incremented
wishes++;
}
What is an else statement?
This statement executes a block of code when the if statement is evaluated as false.
What does the indexOf method return, what is supposed to be returned in the parentheses and what is returned if there is no found character?
The indexOf returns the first occurrence of a character or substring. In the parentheses the code should return the character that you want the index of and if cannot find a character, a -1 will return in the parentheses
What type of variable can’t be changed?
The Final variable
What does modifying a 2D array do?
Modifying a 2D array means changing the values of its elements. This can involve updating, adding, or removing elements at specific positions within the array. Any changes made to a 2D array will affect its structure and the data it contains.
What can cause an infinite loop?
When the condition never evaluates to false.
Ex: Int toys = 10;
while (toys < 11) {
System.out.println("Not enough toys!");
toys--;
}
What is an OR conditional operator?
This conditional operator is the last operator in the order of evaluation.
Why is concat used? And how would you concat these two strings together:
String s1 = “Join";
String s2 = " Code";
Concat is used to combine two or more strings into a new one.
String s3 = s1.concat(s2);
What is it called when you can increase a variable by one?
The increment operator
What is the difference between a 2D array and a 2D list?
A 2D array is a fixed-size data structure that holds elements of the same type in a grid-like format. A 2D list (or list of lists) is a dynamic data structure that can grow or shrink in size and can also hold elements of different types.
What is a for loop?
A loop that can simplify the process of incrementation. Contains initialization, a condition, and an increment.
Ex: for (int i = 0; i < 5; i++) {
//…
}
What is parentheses?
Expressions contained within these will be evaluated in the statement before any other expressions.
When comparing two or more strings together and don’t want to worry about upper/lower case, what would you put?
You would add a equalsIgnoreCase
What is modulo?
Division with the remainder
How can you iterate through a 2D array?
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
What is a For-Each loop?
A loop that can go through each item in a list, performing actions with the elements (for each x : list, do this).
Ex: for(double expense : expenses){
if(expense > mostExpensive){
mostExpensive = expense;
} }
What is a break?
Unless this keyword is present, all cases in the switch statement will be checked.
What does CharAt return? And what will be the result of this code:
String str = “Today is Friday";
System.out.println(str.charAt(0));
This returns the number of characters stated in the parentheses.
The results of the code will be "T"
What are the primitive datatypes?
int, char, Boolean, byte, long, short, double, float