Page 139 - Introduction to Programming with Java: A Problem Solving Approach
P. 139
25. Expression evaluation: a) (7 - n) % 2 *
5 % 2 * 7.5 +
1 * 7.5 + 9 ⇒ 7.5 + 9 ⇒
16.5
7.5 + 9 ⇒ 9 ⇒
b) (4 + n / m) / 6.0 * x ⇒
(4 + 2 / 3) / 6.0 * 7.5 ⇒
(4 + 0) / 6.0 * 7.5 =>
4 / 6.0 * 7.5 ⇒ 0.666666666666666667 * 7.5 ⇒ 5.0
26. count++;
27. count -= 3;
28. number *= (number - 1);
29. For variables declared without an initialization, the initial value is referred to as garbage because its actual value is unknown. Use a question mark to indicate a garbage value.
30. Line numbers tell you which statement in the code generates the current trace results.
31. myInteger = (int) myDouble;
32. The variable, letter, is of type char, but the double quotes in "y" specify that the initial value has type String, so the types aArepinacomgpaotible.PItDshoFuld bEe wnrithtena: ncer
char letter = 'y';
33. To print a double quotation mark, put a backslash in front of it, that is, use \".
34. To print a backslash, use two backslashes, that is, use \\.
35. True.
36. List the primitive types this chapter describes, in the following categories: a) Integer numbers: int, long
b) Floating point numbers: float, double
c) Individual text characters and special symbols: char
37. The + and += operators perform concatenation. The + operator does not update the operand at its left. The += operator does update the operand at its left.
38. The charAt method can be used to retrieve a character at a specified position within a string.
39. The equals and equalsIgnoreCase methods can be used to compare strings for equality.
40. Whitespace the characters associated with the spacebar, the tab key, and the enter key.
41. import java.util.Scanner;
42. Scanner stdIn = new Scanner(System.in);
43. line = stdIn.nextLine();
44. number = stdIn.nextDouble();
Review Question Solutions 105