Java Reference
In-Depth Information
Suppose that score is an int variable. Consider the following if statements:
if (score >= 90);
System.out.println("Discount = 10%");
a. What is the output if the value of score is 95 ? Justify your answer.
b. What is the output if the value of score is 85 ? Justify your answer.
14.
Suppose that score is an int variable. Consider the following if statements:
15.
if (score == 70)
System.out.println("Grade is C.");
i.
if (score = 70)
System.out.println("Grade is C.");
ii.
Answer the following questions:
a. What is the output in (i) and (ii) if the value of score is 70 ? What is the
value of score after the if statement executes?
b. What is the output in (i) and (ii) if the value of score is 80 ? What is the
value of score after the if statement executes?
16. Rewrite the following expressions using the conditional operator. (Assume
that all variables are declared properly.)
a. if (x >= y)
z = x - y;
else
z = y - x;
b. if (hours >= 40.0)
wages = 40 * 7.50 + 1.5 * 7.5 * (hours - 40);
else
wages ΒΌ hours * 7.50;
c. if (score >= 60)
str = "Pass";
else
str = "Fail";
17. Rewrite the following expressions using an if ... else statement. (Assume
that all variables are declared properly.)
(x < 5) ? y = 10 : y = 20;
a.
(fuel >= 10) ? drive = 150 : drive = 30;
b.
(booksBought >= 3) ? discount = 0.15 : discount = 0.0;
c.
Search WWH ::




Custom Search