wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Conditional Construct by Swarn

Total questions: 12

Worksheet time: 36mins

Name
Class
Date
1.

Re-write above statement using ternary operator-

a)

if(X<=Y) then X=Y else Y=X;

b)

if(X<=Y) ? X=Y : Y=X;

c)

(X<=Y) ? X=Y : Y=X;

2.

"if" is a conditional construct?

a)

True

b)

False

3.

What will be the output of following statement-

System.out.println('A'=='a');

a)

A==a

b)

65==97

c)

true

d)

false

4.

What will be the output of above statement-

a)

5

b)

6

c)

No output

d)

Error

5.

What will be the output of above snippet-

a)

1 is greater than 2

b)

2 is greater than 1

c)

No output

d)

Error

6.

What will be the output of following snippet-

a)

Both are not equal

b)

Both are equal

c)

Compilation Error

d)

Runtime Error

7.

Select correct output-

a)

y is 0

b)

y is 2

c)

y is 10

d)

y is 111

8.

What will be the output of following code snippet-

a)

true

b)

false

c)

Compilation Error

d)

Runtime Error

9.

What will be the output of following program snippet-

a)

true

b)

false

c)

Compilation Error

d)

Runtime Error

10.

Which of the following statements is true.

a)

for every 'if' there should be an 'else'.

b)

for every 'else' there should be an 'if'.

c)

'if' block can exist without an 'else'

d)

'if' statement can be used inside another 'if' statement

11.

int marks = 50;

if( marks > 70 )

System.out.println("Distinction");

else if( marks > 35 )

System.out.println("Pass");

else

System.out.println("Fail");

a)

Pass

b)

Distinction

c)

Fail

d)

Pass

Fail

12.

int marks = 80;

if( marks > 70 )

System.out.println("Distinction");

System.out.println("Congratulations");

else if( marks > 35 )

System.out.println("Pass");

a)

Distinction

Congratulations

b)

Pass

c)

Distinction

d)

Error ('else' without 'if')