Exercises 3.3
1. integer
2. real
3. real
4. neither – quotes denote
string literal
5. neither – this is an
expression, not a literal
6. real
7. neither – minus may not
follow literal
8. neither – commas not allowed
9. integer
10. neither – dollar sign not allowed
11. real
12. real
13. neither – missing mantissa
14. neither – variable name
15. neither – exponent must be an integer
16. real
17. neither – this is an expression, not a
literal
18. neither – this is an expression, not a
literal
19. real
20. neither – this is an expression, not a
literal
21. 1 22. 0
23. 0.9 24.
0
25. 0.5 26.
1
27. 2 28.
2
29. 1 30. 2
31.
12 32. 12.5
33.
0 34. –15.0
35. –15.0 36. 18
37. 3 38. 1
39. 3 40. 1001
41. 1101 42. 0100
43. 0011 =
3 44. 110100 = 52
45.
4.0 46. invalid --
Math.sqrt(-4.0) is undefined
47.
4.0 48. 1
49.
2 50. 1
51.
1 52. 7.0
53.
8.0 54. 2
55.
2.66666 . . . 56. 20.0
57.
5.1 58. 4.0
59.
6.25 60. 3.0
61. 10 + 5 * B - 4 * A * C
62. 3 * (4 - n)) / (2 * (m * m +
n * n))
63. Math.sqrt(a + 3 * b * b)
64. Math.sqrt((m + n) / 2)
65. Math.abs(A / (m + n))
66. Math.exp(x * Math.log(a))
67. (int)(cost * 100.0 + 0.5) /
100.0
68. (a) (int)(12.342 * 100.0 + 0.5)
/ 100.0
=
(int)(1234.7)) / 100.0 = 1234.0 / 100.0 = 12.34
(b) (int)(12.348 * 100.0 + 0.5)
/ 100.0
=
(int)(1235.3)) / 100.0 = 1235.0 / 100.0 = 12.35
(c)
(int)(12.345 * 100.0 + 0.5) / 100.0
=
(int)(1235.0)) / 100.0 = 1235.0 / 100.0 = 12.35
(d)
(int)(12.340 * 100.0 + 0.5) / 100.0
=
(int)(1234.5)) / 100.0 = 1234.0 / 100.0 = 12.34
(e)
(int)(13.0 * 100.0 + 0.5) / 100.0
=
(int)(1300.5) / 100.0 = 1300.0 / 100.0 = 13.0
69. x = (int)(x * 10.0 + 0.5) / 10.0;
70. x = (int)(x * 1000.0 + 0.5) /
1000.0;