3.1 <; <=; ==; !=; >; >=
3.2 不能转换。布尔型不能转换到其它类型。
3.3 If number is 30,
(a) displays
30 is even
30 is odd
(b) displays
30 is even
If number is 35,
(a) displays
35 is odd
(b) displays
35 is odd
3.4 第一个没有输出。第二个输出是:z is 7。第三个输出是:x is 2。
3.5 B和C的缩进对。
3.6 第一个没有输出。第二个输出是:x is 3。第三个输出是:z is 6。
3.7 Yes
3.8 0.5; 0.0; 0.234
3.9 (int)(Math.random() * 20)
10 + (int)(Math.random() * 10)
10 + (int)(Math.random() * 41)
3.10 if (y > 0)
x = 1
3.11 if (score > 90)
pay *=1.03;
if (score > 90)
pay *=1.03;
else
pay *= 1.01;
3.12 newLine = (count % 10 == 0);
3.14
(true) && (3 > 4)
false
!(x > 0) && (x > 0)
false
(x > 0) || (x < 0)
true
(x != 0) || (x == 0)
true
(x >= 0) || (x < 0)
true
(x != 1) == !(x == 1)
true
3.15 (x > 1) && (x < 100)
3.16 ((x > 1) && (x < 100)) || (x < 0)
3.17 x > y > 0
incorrect
x = y && y
incorrect
x /= y
correct
x or y
incorrect
x and y
incorrect
3.18 a. x is 2.
b. x is 1.
3.19 If ch is 'A', the expression is true;
If ch is 'p', the expression is false;
If ch is 'E', the expression is true;
If ch is '5', the expression is false;
3.20
2 3 6
(x < y && y < z) is true
(x < y || y < z) is true
!(x < y) is false
(x + y < z) is true
(x + y < z) is true
3.21 age > 13 && age < 18;
3.22 weight > 50 || height > 160.
3.23 weight > 50 && height > 160
3.24 weight > 50 ^ height > 160
3.25 Switch 变量必须是char, byte, short, or int 型数据类型. 如果没用break 结束 , 那么下一个 case statement 被执行. switch 语句转换成等价的if 语句, but not an if statement to a switch statement. The use of the switch statement can improve readability of the program in some cases. The compiled code for the switch statement is also more efficient than its corresponding if statement.
3.26 y 是 2
3.27 switch (a) {
case 1: x += 5; break;
case 2: x += 10; break;
case 3: x += 16; break;
case 4: x += 34;
}
3.28 switch (day) {
case 0: dayName = "Sunday"; break;
case 1: dayName = "Monday"; break;
case 2: dayName = "Tuesday"; break;
case 3: dayName = "Wednesday"; break;
case 4: dayName = "Thurday"; break;
case 5: dayName = "Friday"; break;
case 6: dayName = "Saturday"; break;
}
3.29 System.out.println((count % 10 == 0)? count + "\n" : count + " ");3.30 pay = (temperature > 90) ? pay * 1.5 : pay * 1.1);
3.31 输出布尔值,字符,十进制整数,浮点数和字符串的格式描述符分别是 %b, %c, %d, %f, and %s.
3.32
(a) the last item 3 does not have any specifier.
(b) There is not enough items
(c) The data for %f must a floating-point value
3.33
(a) amount is 32.320000 3.233000e+01
(b) amount is 32.3200 3.2330e+01
(c) *false // * denote a space
(d) **Java // * denote a space
(e) false*****Java*falseJava
3.34 Use the String.format method to create a formatted string.
3.35 运算符顺序是:^, &&, and ||
true || true && false is true
true && true || false is true
3.36 True