WorksheetsAP CSA Unit 3
Total questions: 34
Worksheet time: 1hrs 15mins
What does short circuit evaluation mean in the following code?
i) if (a < b && c != d)
if a < b is false it evaluates c != d
if a < b is false it doesn't evaluate c != d
if c != d is false it evaluates a < b
f c != d is false it doesn't evaluate a < b
if a < b is true it doesn't evaluate c != d
Which if statement below tests if the variable letter holds the char value #?
if (letter == #)
if (letter == "#")
if (letter == '#')
if (letter >= '#')
if (letter = '#')
What is 0 0 1 1 1 0 0 0 in base ten?
54
55
56
57
58
What is 67 in binary?
0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 1
0 1 0 0 0 1 1 0
0 1 0 0 0 1 1 1
0 1 0 0 1 1 1 0
Consider the following code:
String w = "Rapunzel";
for (int i = 0; i < w.length(); i++) {
System.out.print(w.charAt(i) + " ");
if (i%4 == 3)
System.out.println();
}
What is output?
R a p u
n z e l
R a p
n z e l
R a p u n z e l
u l
R a p n z e
What does the String method substring() do?
Returns a portion of the String.
Tests two String objects for equality.
Compares this String with a second String for greater than, equal to, or less than.
Returns the character at a certain location as a char value.
Returns the length of a String.
What does the following code do?
String w3 = "aardvark";
System.out.println(w3.charAt(w3.length() – 2));
Prints the second letter in the String.
Prints the second to last letter in the String.
Prints the last letter in the String.
Prints the first letter in the String.
Causes an index out of bounds error.
Consider the following code:
String major = "Computer Science";
What is returned by the method call major.charAt(2)?
'C'
'o'
'm'
"C"
"Science"
What is the result of 3/2 in Java?
1.5
1.0
1
0
What is the result of 3.0/2 in Java?
1.5
1.0
1
0
What is the result of 3%2?
1
1.5
1.0
0
What is the result of 2%1?
0
1
2
This cannot be calculated.
What is the difference between primitive variables and Object reference variables?
Primitive variables hold a variable's value, whereas Object reference variables do not a value, they point to it .
Primitive variables take up a specific amount of memory, whereas the amount of memory an Object reference can take up varies.
Both answers are correct.
Where does modulus fall within the PEMDAS order of operations?
After multiplication and division
Before multiplication and division
At the same level of multiplication and division
Whenever you feel like it.
Which statement is an incorrect attempt at instantiating a String object?
new String("hi!");
String s = new String("hi!");
String s = "hi!";
String s = String("hi!");
Data types hold the memory address of where the data is stored:
null
class
primitive
alphanumeric
A variable that goes out of scope is
garbage collected
tested
referenced
instantiated
True/False: It is possible to change the length of arrays during run time
True
False
True/False: Arrays can hold more than one type of data
True
False
Is the following binary number Even or Odd:
0111001
even
odd
The elements in arrays of type double are initialized to
null
0
0.0
they are not initialized
String [] name = { "Anne"};
What is the value of name.length;
0
1
3
4
5
String [] fruits = {"apple", "peach", "banana", "tomato"};
What is fruits[2].length() equal?
4
5
6
what is 2 to the zero power?
0
1
2
What is the function of the break statement?
A loop that contains the break statement is terminated and the program continues to execute.
the break statement is used to return a value from a method.
The break statement is used when the computer experiences a run-time error.
The break statement should never be used.
In base 8, what comes after 7?
8
10
11
17
Which of the following is in 8 bit form?
1000 0000
1101
11 1110
8
What does this statement do?
int [] nums = new int[8];
creates an array of 8 integers called nums
creates a single variable name nums that contains an 8 digit number
creates a single variable named nums that is initialized to 8.
String str1 = "bats";
String str2 = "buns";
str1.compareTo(str2)
returns 0
returns a positive number
returns a negative number
int n1 = 12;
int n2 = 5
int ans = n1/n2
What is the value at ans?
1
2
2.4
