The expression "baseball".substring(0,4) returns "base".
True
the .substring command returns the character from the first position (0) and DOES NOT print the character at the second position (4).
A data type in Java that has the values true or false.
Boolean
Declare a 2-D array of double values called realMat that has 2 rows and 8 columns.
double [] [] realMat = new double [2] [8];
If an array, arr contains 100 int values, what does the following statement do?
int x = arr[100];
ArrayOutOfBoundsException.
arr[99] is the last term.
3 + 4 * 8 / 3 - 12
1
If String s1 = "4" ; and if String s2 = "3"; then the statement String s3 = s1+s2 will assign the String value "7" to s3.
False
The + operator is a concatenation operator which chains strings together. s3 would contain "43".
A block of code that is used to create an object of a class. It looks like a method but it's not a method.
The heading also shares the same name as the class it belongs to.
Constructor
If an ArrayList<Integer> called list is initialized, write a statement that stores in int n, the number of elements in the list.
int n = list.size();
If A is a boolean variable whose value is false, B is a boolean variable whose values is true. and if C is a boolean variable with value false, what will be returned by the following statement?
return A || B && C;
False
AND comes before OR on Order of Operations chart!
false OR (true AND false)
How many times will the following loop be executed?
for(int j = 1; j <= 10; j+=2){
}
5 times
1, 3, 5, 7, 9
If a code segment contains an attempt to perform integer division by zero, a run-time error will occur.
True
The program will compile properly. An ArithmeticException will be thrown at run-time.
When the subexpressions in a compound Boolean expression are evaluated from left to right, and calculations automatically stop.
Ex. Given, A || B. If A is true, the whole expression is true and B is not considered.
Short-curcuit evaluation
Write a statement that stores in a double value realNum the absolute value of a double variable called x.
double realNum = Math.abs(x);
Suppose the a string variable is declared as follows:
String word = "tomato";
What will be the result of the line below?
String numby = word.indexOf("o");
Compile error.
numby should be an integer.
Convert from binary to decimal form:
1011
11
1101 = 1(8) + 0(4) + 1(2) + 1(1)
If a two-dimensional array mat is declared as follows:
int [] [] mat = new int [3] [4];
the the expression mat[3][4] represents the slot in the bottom right-hand corner of the matrix.
False
The expression mat[3][4] is out of bounds. An ArrayIndexOutOfBoundsException will be throwing.
mat[2][3] will be the bottom right-hand corner.
DAILY DOUBLE
What is your wager?
Logical Operator ! && ||
Relational Operator < > <= >= == !=
Arithmetic Operator + - / * %
Write a statement that stores in a double variable called power, the number 4 raised to the 5th power.
double power = Math.pow(4, 5);
If sum is an int variable whose value is 12 and if amount is a double variable with value 8, what will be returned by the following statement?
return sum/amount;
1.5
Floating point division occurs if at least one of the operands is a real number.
What is the result of "catastrophe".substring(4, 9);?
"strop"
The scope of a local variable is the method in which the variable is declared.
False
The scope of any variable is the block {} in which the variable is declared. It can be a method, a single loop within a method, etc.
These are methods (2 or more) with the same name in the same class with a different number/type of parameters.
Overloaded methods
The relationship between the radius of a circle in terms of its area is given by:
r = sq(A/pi)
Assuming radius and area have been correctly declared and that there is a real-value constant for pi. Convert this into one line of Java code.
radius = Math.sqrt(area/Math.PI);
What will be the effect of executing the following code given that int num1 is 0 and int num2 is 10?
if(num1 / num2 < 0) || (num1 + num2 > 0)
statement1;
else
statement2;
statement1 will be executed.
How many times will the loop be executed?
for(int j = 1; j <= 3; j++){
for(int k = 1; k <=2; k++){
}
}
6 times
j = 1 and k = 1
j = 1 and k = 2
j = 2 and k = 1
j = 2 and k = 2
j = 3 and k = 1
j = 3 and k = 2