Font size
WorksheetsConditional Construct by Swarn
Total questions: 12
Worksheet time: 36mins
Re-write above statement using ternary operator-
if(X<=Y) then X=Y else Y=X;
if(X<=Y) ? X=Y : Y=X;
(X<=Y) ? X=Y : Y=X;
"if" is a conditional construct?
True
False
What will be the output of following statement-
System.out.println('A'=='a');
A==a
65==97
true
false
What will be the output of above statement-
5
6
No output
Error
What will be the output of above snippet-
1 is greater than 2
2 is greater than 1
No output
Error
What will be the output of following snippet-
Both are not equal
Both are equal
Compilation Error
Runtime Error
Select correct output-
y is 0
y is 2
y is 10
y is 111
What will be the output of following code snippet-
true
false
Compilation Error
Runtime Error
What will be the output of following program snippet-
true
false
Compilation Error
Runtime Error
Which of the following statements is true.
for every 'if' there should be an 'else'.
for every 'else' there should be an 'if'.
'if' block can exist without an 'else'
'if' statement can be used inside another 'if' statement
int marks = 50;
if( marks > 70 )
System.out.println("Distinction");
else if( marks > 35 )
System.out.println("Pass");
else
System.out.println("Fail");
Pass
Distinction
Fail
Pass
Fail
int marks = 80;
if( marks > 70 )
System.out.println("Distinction");
System.out.println("Congratulations");
else if( marks > 35 )
System.out.println("Pass");
Distinction
Congratulations
Pass
Distinction
Error ('else' without 'if')
