wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Basic Algorithms Quiz: Assignment Statements

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What will be printed after executing this code?

a)

5

b)

8

c)

3

d)

13

2.

What is the value of `result` after this code executes?

a)

3

b)

1

c)

2

d)

0

3.

What will print?

a)

Java

b)

Programming

c)

Java Programming

d)

Compilation Error

4.

Given the code: What is the output?

a)

3.75

b)

3

c)

4

d)

15

5.

After execution, what is `count`?

a)

0

b)

4

c)

5

d)

6

6.

How many times will this loop execute?

a)

4 times

b)

5 times

c)

6 times

d)

Infinite loop

7.

What is the output of this loop?

a)

a) 0 1 2

b)

b) 1 2 3

8.

What will this code print?

a)

4

b)

9

c)

10

d)

1234

9.

Which loop is most efficient for iterating exactly 100 times?

a)

a) `while(true)` loop

b)

b) `for(int i = 0; i < 100; i++)`

c)

c) `do-while` loop

d)

d) `for(int i = 0; i <= 100; i++)`

10.

What does this loop print?

a)

a) 5 4 3 2 1

b)

b) 5 4 3 2

c)

c) 2 3 4 5

d)

d) 1 2 3 4 5

11.

What is the output?

a)

10

b)

20

c)

30

d)

40

12.

What is the length of this array?

a)

0

b)

2

c)

3

d)

4

13.

What will this code print?

(this one is just a bit tricky)

a)

0

b)

null

c)

5

d)

Compilation Error

14.

What is the output?

a)

5

b)

10

c)

15

d)

25

15.

What does this code do?

(there are two things in this code you haven't had, but I know you can figure it out. Not a trick)

a)

Prints: a b c

b)

Declares an array of characters

c)

Loops through the array

d)

Prints the length of the array

16.

What is the output?

You haven't had chartAt(i) but it's a shortcut for substring(I,I+1)

a)

H

b)

e

c)

l

d)

I don't know what's i

17.

What will print?

a)

3

b)

4

c)

5

d)

J

18.

What is the result?

a)

Pro

b)

Pr

c)

Program

d)

Programming

19.

What does this print?

a)

JAVA

b)

java

c)

Java

d)

JaVa

20.

What is the output?

a)

true

b)

false

c)

Code

d)

Compilation Error