NEW
Font size
WorksheetsUnit 2 Quiz review
Total questions: 23
Worksheet time: 12mins
What is the name of the method to print out text in Java?
System.out.println()
System.out.printline()
System.output()
System.out.PRINTLN()
What is the output of the following lines? int x = 24; System.out.println("The total is + x + x);
The total is 24
The total is 2424
The total is 48
The total is x + x
Which of the following is not a primitive type?
int
double
String
boolean
char
What is the value of x after this code? int x = 5; x = 10; x = 4;
5
10
4
true
What is the proper syntax to initialize a double called temperature to have the value 70.4?
int temperature = 70.4;
double temperature = 70.4;
temperature = 70.4;
float temperature = 70.4;
What is the result of this expression? Assume all numbers are int. 5 + 2/3 + 1
5
6
6.67
0
Which expression returns the 1's place of an integer x?
x % 10
x/10
x % 100
x + 1
What is the value of myInteger after this line of code? int myInteger (int) 5.6;
6
5.5
5
9
Which expression is true?
true && !true
!false || !true
true && false
false Il false || !true
Which of these is not a logical operator?
&&
!
||
++
What is the output of this for loop?
10
7
4
10
7
4
1
1
2
3
10
8
6
4
2
What is the output of this for loop?
The Even numbers from 0-98 inclusive
The Even numbers from 0 to 100 inclusive
all of the numbers from 0 to 100
The odd numbers from 0 to 98 inclusive
How many times will the loop execute?
0
4
5
50
What will this code output?
Hello Karel
Hello Karel
Second if statement!
<this program prints nothing.
Second if statement!
What will this program print if the value of grade is 80?
a
b
c
nothing
What output will be produced by System.out.println("Hello"); System.out.println("Karel");
Hello Karel
HelloKarel
Hello
Karel
<error>
What will the values of x and y be after this code segment runs?
x=100, y = 200
x=101, y = 100
x=101, y=201
x=99, y = 199
What will the code segment output? **note the use of print() and not println()
*
**
***
****
*****
*****
****
***
**
*
*****
*****
*****
*****
*****
**********
Refer to the following code segment: Which change to the first line of their code segment would get the student the answer that they wanted?
int myDouble = 1/4;
double myDouble = (double) 1/4;
double myDouble = (int) (1.0/4.0);
double myDouble = (int) 1/4;
What is the result of this expression? Modulo happens during the multiplication and division step. 4 + 8 3 / 4 + 5 % 2
5
6
12
11
Which of these is not a valid Java method name?
spin10Times
10TimesMove
moveTenTimes
spinTenTmes
What in this code segment could potentially cause a bug in our program?
syntax error
nothing
Storing a line in a string
using == not .equals() for strings
What is the output of this program?
Welcome to the adding machine!
1
2
4
8
16
Welcome to the adding machine!
2
4
8
16
Welcome to the adding machine!
2
4
8
<output is an infinite loop>
