wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java test 02

Total questions: 30

Worksheet time: 1hrs 18mins

Name
Class
Date
1.
Boolean values are: 
a)
True / False
b)
Yes / No
c)
Right / Wrong
2.

Is "X" printed?

a)

YES

b)

NO

3.

Is "X" printed?

a)

YES

b)

NO

4.

Click ALL answers which result in an "X" printed.

a)

a = 3, b = 3, c = 3

b)

a = 5, b = 4, c = 7

c)

a = 1, b = 3, c = 5

d)

a = 6, b = 4, c = 3

e)

a = 5, b = 5, c = 3

5.

What is output?

a)

0

b)

1

c)

2

d)

3

6.

What is output?

a)

-1

b)

0

c)

1

d)

2

7.

What is output?

a)

-1

b)

0

c)

1

d)

2

8.

Given : a = 1, b = 2

if ( missing ) print "X"


Select ALL expressions which can be used for missing to result in an "X" being printed.

a)

a < 2

b)

a != b

c)

a > b

d)

b >= a

e)

b == a

9.

Which expression is the same as (a != b) ?

a)

! (a == b)

b)

! (a >= b)

c)

! (a < b)

d)

! (b >= a)

10.

Which expression is the same as (a == b) ?

a)

! (a != b)

b)

! (a >= b)

c)

! (a < b)

d)

! (b >= a)

11.

Given : a = 1, b = 2

if ( missing ) print "X"


Select ALL expressions which can be used for missing to result in an "X" being printed.

a)

a < 2 && b == 2

b)

a != b || a == b

c)

a > b

d)

! (b >= a)

e)

b == a

12.

Which is the alternative to SWITCH in Java language?

a)

break, continue

b)

for, while

c)

if-else

d)

goto, exit

13.

A SWITCH statement accepts ___ type of data as input.

a)

byte

b)

short

c)

int

d)

String (case sensitive)

e)

All of above

14.

What is the output of Java program with SWITCH below?


int a=10;

switch(a)

{

case 2: System.out.println("TWO");

break;

case 10: System.out.println("TEN");

break;

}

a)

No Output

b)

TEN

c)

Compiler error as there is no break

d)

None

15.

Which way is a correct way to write an if statement in Java?

a)

if (1 > 0)

{

System.out.println("1 is greater than 0");

}

b)

if (1 > 0) ;

{

System.out.println("1 is greater than 0");

}

c)

if (1 > 0)

[

System.out.println("1 is greater than 0");

]

d)

If (1 > 0)

{

System.out.println("1 is greater than 0");

};

16.

What is output by the code? Pretend it says System.out.println

a)

2

b)

3

c)

4

d)

5

e)

6

17.

What is output by the code?

a)

123

b)

12

c)

1234

d)

12345

e)

4321

18.
a)

1 2 4 8 16 32 64

b)

1 2 4 8 16 32

c)

2 4 8 16 32 64

d)

2 4 8 16 32

e)

4 8 16 32 64

19.
a)

200 66 22 7 2

b)

66 22 7 2

c)

200 66 22 2

d)

200 66 22

e)

7

20.

How many stars are printed?

a)

7

b)

3

c)

4

d)

5

e)

Infinite Loop

21.

How many times does the loop print a *

a)

40

b)

20

c)

24

d)

30

e)

Infinite Loop

22.

What does the following code print?

a)

5 6 7 8 9

b)

4 5 6 7 8 9 10 11 12

c)

3 5 7 9 11

d)

3 4 5 6 7 8 9 10 11 12

23.

How many times does the following method print a *?

a)

9

b)

6

c)

7

d)

10

24.
a)

1 2 4 8 16 32 64

b)

1 2 4 8 16 32

c)

2 4 8 16 32 64

d)

2 4 8 16 32

e)

4 8 16 32 64

25.
a)

10

b)

15

c)

17

d)

22

e)

25

26.

2

a)

5

b)

7

c)

9

d)

13

e)

20

27.

What is output by the code? Pretend it says System.out.println

a)

2

b)

3

c)

4

d)

5

e)

6

28.

What is ouptut by the code? Pretend it says System.out.println

a)

2

b)

3

c)

4

d)

5

e)

6

29.

What is output by the code?

a)

123

b)

12

c)

1234

d)

12345

e)

4321

30.

Pretend it says System.out.println

a)

1383

b)

83

c)

1813

d)

181383

e)

1318