wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Lesson 2

Total questions: 7

Worksheet time: 6mins

Name
Class
Date
1.

if(apples are red) System.out.print("Hello"); if(apples are blue) System.out.print("Bye"); __ ____What is the output?______

(a)  

2.

How many choices are possible when using a single if-else statement?

a)

1

b)

2

c)

3

d)

4

3.

What does the following output?

int sum = 45;

if ( sum < 20 )

{

System.out.println(Under);

}

else

{

System.out.println(Over);

}

a)

Over

b)

Under

c)

Nothing

d)

Error

4.

there is if, ________ ___, and else statements

(a)  

5.

What does the following output?

int sum = 45;

if ( sum < 20 )

{

System.out.println("Under");

}

else

{

System.out.println("Over");

}

a)

Over

b)

Under

c)

Nothing

d)

Compilation error

6.

What is the output?

________________________________________

double grade=102.4

switch(int(grade/10)) {

case 10 :

case 9 :

System.out.println("F");

break;

case 8 : System.out.println("B"); break;

case 7 :

System.out.println("C");

break;

case 6 :

System.out.println("D");

break;

default :

System.out.println("F");

}

return 0;

}

a)

A

b)

B

c)

Prints nothing

d)

F

7.

for(int i=0;i<15; (a)   ){

System.out.print(i+" ");

}

If the output is

1 2 3 4 ... 15

what is the missing line?