Java Reference
In-Depth Information
9. 3 1
11. 1 3
13. if (0 < overSpeed && overSpeed <= 5)
fine = 20.00;
else if (5 < overSpeed && overSpeed <= 10)
fine = 75.00;
else if (10 < overSpeed && overSpeed <= 15)
fine = 150.00;
else if (overSpeed > 15)
fine = 150.00 + 20.00 * (overSpeed - 15);
15.
a.
i. The output is: Grade is C . The value of score after the if statement
executes is 70 .
ii. The expression score ¼ 70 in statement ii will result in a syntax error.
b.
i. No output. The value of score after the if statement executes is 80 .
ii. The expression score ¼ 70 in statement ii will result in a syntax error.
17.
a. if (x < 5)
y = 10;
else
y = 20;
b. if (fuel >= 10)
drive = 150;
else
drive = 30;
c. if (booksBought >= 3)
discount = 0.15;
else
discount = 0.0;
19. a is invalid: The expression n < ¼ 2 evaluates to a boolean value, which is not an
integral type. The expression in the switch expression must evaluate to an integral
value. b is invalid: A case value cannot appear more than once. c and d are valid.
21. 7
23. There is more than one answer. One possible answer is:
import java.util.*;
public class Errors
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int a, b;
Search WWH ::




Custom Search