3.2.1. Selection-WE2-P1ΒΆ
Subgoals for Evaluating Selection Statements
Diagram which statements go together.
For if-statement, determine whether expression is true or false.
If true, follow true branch. If false, follow else branch (OR do nothing if there is no else branch).
Select-WE2-P1
Each question below is independent, but they all use this given setup
int alpha = 2, beta = 1, delta = 3, eta = 0, gamma = 0;
double omega = 2.5, theta = -1.3, kappa = 3.0, lambda = 0.0, rho = 0.0;
- 0 is true
- 0 is false
- There is no output because a compiler error occurs
- There is no output because an exception occurs
Q6: What is the output of the following code?
int x = 0;
if (x = 0) /* look closely! */
System.out.println("0 is true");
else
System.out.println("0 is false");
- it is true
- it is false
- There is no output because a compiler error occurs
- There is no output because an exception occurs
Q7: What is the output of the following code?
if (false)
System.out.println("it is true");
else
System.out.println("it is false");
- Never
- Always
- There is no output because a compiler error occurs
- There is no output because an exception occurs
Q8: What is the output of the following code?
if (12 < 12)
System.out.println("Never");
else
System.out.println("Always");
- O.K.
- Not O.K.
- There is no output because a compiler error occurs
- There is no output because an exception occurs
Q9: What is the output of the following code?
double var1 = 15.0;
double var2 = 25.12;
if (2 * var1 >= var2)
System.out.println("O.K.");
else
System.out.println("Not O.K.");
You have attempted of activities on this page