NEW
Font size
S
M
L
XL
WorksheetsChapter 2 Review
Total questions: 25
Worksheet time: 49mins
Name
Class
Date
1.
In Java, 5 / 2 =...
a)
2
b)
2.5
c)
3
d)
None of the above
2.
In Java, % refers to...
a)
percentages
b)
modulus operator
c)
division
d)
data storage
3.
The following statement is valid: double price = 4,248.09;
a)
True
b)
False
4.
In Java, 13 % 5 =...
a)
1
b)
2
c)
3
d)
4
5.
Which of the following is a legal variable name in Java?
a)
1test
b)
int
c)
value
d)
n.1
6.
Which of the following variable declarations is a correct assignment?
a)
double y = 82;
b)
int x = 97.2;
c)
char c = 65.5;
d)
String i = 82;
7.
What is output?
int val = -2;
val++;
val--;
val++;
val++;
val++;
val--;
System.out.println(val);
int val = -2;
val++;
val--;
val++;
val++;
val++;
val--;
System.out.println(val);
a)
-2
b)
-1
c)
0
d)
1
8.
Correct the following code:
double q = 6;
double q = 6;
a)
int q = (double) 6;
b)
int q = int (6);
c)
int q = (int) 6;
d)
No changes, the code is fine
9.
What is output?
int a = 91;
System.out.println(a / 2);
int a = 91;
System.out.println(a / 2);
a)
44
b)
45
c)
45.5
d)
46
10.
Which symbol correctly completes the following variable declaration?
char c = _ g _; (Fill the blanks)
char c = _ g _; (Fill the blanks)
a)
"
b)
'
c)
+
d)
%
11.
Put the following data types in order from smallest to largest (in terms of memory used).
a)
double < char < int < String
b)
int < char < double < String
c)
char < int < double < String
d)
double < int < char < String
12.
Which of the following is modular division NOT used for?
a)
patterns
b)
even and odd numbers
c)
converting decimals to whole numbers
d)
time calculations
13.
What is output?
System.out.println("The answer is: " + 5 + 19);
System.out.println("The answer is: " + 5 + 19);
a)
The answer is: 519
b)
The answer is: 19
c)
The answer is: 24
d)
The answer is: 5 19
14.
What is output?
int c = 3 - 37 % 2;
System.out.println(c);
int c = 3 - 37 % 2;
System.out.println(c);
a)
-18
b)
2
c)
3
d)
18
15.
Which of the following variable assignments is legal in Java?
a)
double n = 3;
b)
String w = 82.5;
c)
char x = "G";
d)
int y = 5.0 / 2;
16.
What's wrong with the following code?
double x = 7.4549;
double x = 7.4549;
a)
The decimal portion will be truncated.
b)
Decimals can only have 2 places.
c)
You must cast since integers hold less information than doubles.
d)
There is nothing wrong.
17.
Which of the following would properly created a and b as integer variables?
a)
a, b int;
b)
int a b
c)
int a, b;
d)
int a; b;
18.
Fill in the blank so the for loop will output 2 4 6 8 10
for (int i = _; i _; i _){
System.out.print( i + " ");
}
for (int i = _; i _; i _){
System.out.print( i + " ");
}
a)
2, < 10, += 2
b)
0, < 10, += 2
c)
2, <= 10, ++
d)
2, <= 10, += 2
19.
Fill in blanks so the for loop outputs 10 9 8 7 6 5 4 3 2 1
for (int i = _; i _; i _) {
System.out.print( i + " ");
}
for (int i = _; i _; i _) {
System.out.print( i + " ");
}
a)
10, > 1, --
b)
10, >= 1, --
c)
10, >= 1, ++
d)
9, >= 1, --
20.
What's output?
for (int i = 0; i <= 5; i++){
System.out.print( i + " ");
}
for (int i = 0; i <= 5; i++){
System.out.print( i + " ");
}
a)
0 1 2 3 4 5
b)
0 1 2 3 4
c)
1 2 3 4
d)
1 2 3 4 5
21.
What is output?
for (int t = 32; t <= 100; t += 22) {
System.out.print( t + " ");
}
for (int t = 32; t <= 100; t += 22) {
System.out.print( t + " ");
}
a)
32 33 34 35
b)
32 54 76 98
c)
32 54 76
d)
32 54 76 100
22.
What is 0101 1101 in base 10?
a)
91
b)
92
c)
93
d)
94
23.
What is NOT true about class constants?
a)
They cannot change their value.
b)
They are only used within the class.
c)
They cannot be used in expressions.
d)
The name for the constant has to be in all upper case letters.
24.
What is pseudocode?
a)
A basic word description of your code.
b)
It is code that codes itself.
c)
It is fake.
d)
Just don't pick this one.
25.
Other concepts on test: nested for loops, looking for errors, and scope. Push the right button.
a)
Don't pick this one.
b)
You could pick this one, but I wouldn't.
c)
It is definitely not this one.
d)
Hi!
Reset
