0% found this document useful (0 votes)
21 views6 pages

Revision Lecture6

This document contains a lecture on if-else statements in Java including: - True/false questions about if-else statement syntax and functionality - Code snippets testing different if/else conditional expressions and blocks - Questions about if/else statements, decision making statements, and conditional expressions in Java The lecture covers the basic syntax and usage of if-else statements, conditional expressions, and decision making in Java programs.

Uploaded by

amrahmed0159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Revision Lecture6

This document contains a lecture on if-else statements in Java including: - True/false questions about if-else statement syntax and functionality - Code snippets testing different if/else conditional expressions and blocks - Questions about if/else statements, decision making statements, and conditional expressions in Java The lecture covers the basic syntax and usage of if-else statements, conditional expressions, and decision making in Java programs.

Uploaded by

amrahmed0159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lecture 6

T/F

1 One if can have more than one else clause. F


2 In if statement; the condition must be an expression of type T
Boolean.

1. How many choices are possible when using a single if-else statement?
a. 1
b. 2
c. 3
d. 4
2. What does the following code fragment write to the monitor?
int sum = 14;
if ( sum < 20 )
System.out.print("Below ");
else
System.out.print("Over ");
System.out.println("the limit.");
a. Below
b. Over
c. Below the limit.
d. Over the limit.
3. What does the following code fragment write to the monitor?
int sum = 14;
if ( sum < 20 )
System.out.print("Below ");
else
{
System.out.print("Over ");
System.out.println("the limit.");
}
(Notice that the program has changed from the previous question!)
a. Below
b. Over
c. Below the limit.
d. Over the limit.

Page 1 of 6
4. What does the following code fragment write to the monitor?
int sum = 94;
if ( sum < 20 )
{
System.out.print("Below ");
System.out.println("the limit.");
}
else
{
System.out.print("Over ");
System.out.println("the limit.");
}
(Notice that the program has changed from the previous question!)
a. Below
b. Over
c. Below the limit.
d. Over the limit.

5. What does the following code fragment write to the monitor?


int sum = 7;
if ( sum > 20 )
{
System.out.print("You win ");
}
else
{
System.out.print("You lose ");
}
System.out.println("the prize.");
(Notice that the program has changed from the previous question!)
a. You win
b. You lose
c. You win the prize.
d. You lose the prize.

Page 2 of 6
6. What does the following code fragment write to the monitor?
int sum = 21;
if ( sum == 20 )
{
System.out.print("You win ");
}
else
{
System.out.print("You lose ");
}
System.out.println("the prize.");
(Notice that the program has changed from the previous question!)
a. You win
b. You lose
c. You win the prize.
d. You lose the prize.

7. What does the following code fragment write to the monitor?


int sum = 21;
if ( sum != 20 )
System.out.print("You win ");
else
System.out.print("You lose ");
System.out.println("the prize.");
(Notice that the program has changed from the previous question!)
a. You win
b. You lose
c. You win the prize.
d. You lose the prize.

8. A sequence of statements contained within a pair of braces ("{" and "}") is


called a:
a. block
b. blob
c. branch
d. brick

Page 3 of 6
9. Evaluate (to true or false) each of the following expressions:
14 <= 14 14 == 14
a. true true
b. false true
c. true false
d. false false
10.Evaluate (to true or false) each of the following expressions:
14 >= 14 14 < 14
a. true true
b. false true
c. true false
d. false false
11.Evaluate (to true or false) each of the following expressions:
-25 > -9 -9 > -25
a. true true
b. false true
c. true false
d. false false
12.Evaluate (to true or false) each of the following expressions:
14 > 14 -25 > -9
a. true true
b. false true
c. true false
d. false false
13.Say that value has a 19 stored in it, and that extra has a 25 stored in it.
Evaluate (to true or false) each of the following expressions:
value <= extra extra == value
a. true true
b. false true
c. true false
d. false false
14.Say that value has a 19 stored in it, and that extra has a 25 stored in it.
Evaluate (to true or false) each of the following expressions:
value >= extra extra > value
a. true true
b. false true
c. true false
d. false false

Page 4 of 6
15.Say that value has a 19 stored in it, and that extra has a 25 stored in it.
Evaluate (to true or false) each of the following expressions:
value != extra extra > value
a. true true
b. false true
c. true false
d. false false
16.Say that value has a 19 stored in it, and that extra has a 25 stored in it.
Evaluate (to true or false) each of the following expressions:
value >= extra extra == value
a. true true
b. false true
c. true false
d. false false
17.The Java if statement:
a. Evaluates whether an expression is equal or not
b. Evaluates whether an expression is true or false
c. Evaluates whether an expression is less than or more than a number
d. None of the above
18.Which of the following is a decision-making statement?
a. if-else
b. do-while
c. for
d. while
19.Which of these is a selection statement in Java?
a. for
b. while
c. if-else
d. do-while
20.The conditional statement; ........... can evaluate any type of Boolean
expression
a. for
b. while
c. do-while
d. if-else

Page 5 of 6
21.What will be the output of the following code fragment?
int a=25;
int b=15;
if((a15)
System.out.println(a);
else
System.out.println(b);
a. Error
b. 1525
c. 15
d. 25

22.What will be the output of the following code fragment?


int a=25;
int b=15;
if(a==17)
System.out.println(a);
else
System.out.println(b);
(Notice that the program has changed from the previous question!)
a. Error
b. 17
c. 15
d. 25

Page 6 of 6

You might also like