wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Unit 2 Quiz review

Total questions: 23

Worksheet time: 12mins

Name
Class
Date
1.

What is the name of the method to print out text in Java?

a)

System.out.println()

b)

System.out.printline()

c)

System.output()

d)

System.out.PRINTLN()

2.

What is the output of the following lines? int x = 24; System.out.println("The total is + x + x);

a)

The total is 24

b)

The total is 2424

c)

The total is 48

d)

The total is x + x

3.

Which of the following is not a primitive type?

a)

int

b)

double

c)

String

d)

boolean

e)

char

4.

What is the value of x after this code? int x = 5; x = 10; x = 4;

a)

5

b)

10

c)

4

d)

true

5.

What is the proper syntax to initialize a double called temperature to have the value 70.4?

a)

int temperature = 70.4;

b)

double temperature = 70.4;

c)

temperature = 70.4;

d)

float temperature = 70.4;

6.

What is the result of this expression? Assume all numbers are int. 5 + 2/3 + 1

a)

5

b)

6

c)

6.67

d)

0

7.

Which expression returns the 1's place of an integer x?

a)

x % 10

b)

x/10

c)

x % 100

d)

x + 1

8.

What is the value of myInteger after this line of code? int myInteger (int) 5.6;

a)

6

b)

5.5

c)

5

d)

9

9.

Which expression is true?

a)

true && !true

b)

!false || !true

c)

true && false

d)

false Il false || !true

10.

Which of these is not a logical operator?

a)

&&

b)

!

c)

||

d)

++

11.

What is the output of this for loop?

a)

10
7
4

b)

10
7
4
1

c)

1
2
3

d)

10
8
6
4
2

12.

What is the output of this for loop?

a)

The Even numbers from 0-98 inclusive

b)

The Even numbers from 0 to 100 inclusive

c)

all of the numbers from 0 to 100

d)

The odd numbers from 0 to 98 inclusive

13.

How many times will the loop execute?

a)

0

b)

4

c)

5

d)

50

14.

What will this code output?

a)

Hello Karel

b)

Hello Karel
Second if statement!

c)

<this program prints nothing.

d)

Second if statement!

15.

What will this program print if the value of grade is 80?

a)

a

b)

b

c)

c

d)

nothing

16.

What output will be produced by System.out.println("Hello"); System.out.println("Karel");

a)

Hello Karel

b)

HelloKarel

c)

Hello
Karel

d)

<error>

17.

What will the values of x and y be after this code segment runs?

a)

x=100, y = 200

b)

x=101, y = 100

c)

x=101, y=201

d)

x=99, y = 199

18.

What will the code segment output? **note the use of print() and not println()

a)
  • *

  • **

  • ***

    ****
    *****

b)

*****
****

***

**

*

c)

*****

*****

*****

*****

*****

d)

**********

19.

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?

a)

int myDouble = 1/4;

b)

double myDouble = (double) 1/4;

c)

double myDouble = (int) (1.0/4.0);

d)

double myDouble = (int) 1/4;

20.

What is the result of this expression? Modulo happens during the multiplication and division step. 4 + 8 3 / 4 + 5 % 2

a)

5

b)

6

c)

12

d)

11

21.

Which of these is not a valid Java method name?

a)

spin10Times

b)

10TimesMove

c)

moveTenTimes

d)

spinTenTmes

22.

What in this code segment could potentially cause a bug in our program?

a)

syntax error

b)

nothing

c)

Storing a line in a string

d)

using == not .equals() for strings

23.

What is the output of this program?

a)

Welcome to the adding machine!

1

2

4

8

16

b)

Welcome to the adding machine!

2

4

8

16

c)

Welcome to the adding machine!

2

4

8

d)

<output is an infinite loop>