JavaÁ·Ï°Ìâ1£¨Óд𰸣© ÏÂÔØ±¾ÎÄ

µÚ 49Ìâ Analyze the following code fragments that assign a boolean value to the variable even. Code 1: if (number % 2 == 0) even = true; else even = false; Code 2:

even = (number % 2 == 0) ? true: false; Code 3: even = number % 2 == 0;

1¡¢ Code 2 has a compile error, because you cannot have true and false literals in the conditional expression.

2¡¢ Code 3 has a compile error, because you attempt to assign number to even.

3¡¢ All three are correct, but Code 1 is preferred. 4¡¢ All three are correct, but Code 2 is preferred. 5¡¢ All three are correct, but Code 3 is preferred.

´ð°¸ 5 µÚ 50Ìâ The statement System.out.printf(\1234.56) outputs ___________. 1¡¢ 0.1e+04 2¡¢ 0.123456e+04 3¡¢ 0.123e+04

4¡¢ 1.2e+03 5¡¢ 1.23+03 ´ð°¸ 4 µÚ 51Ìâ Analyze the following code: int i = 3434; double d = 3434; System.out.printf(\

1¡¢ The code compiles and runs fine to display 3434.0 3434.0. 2¡¢ The code compiles and runs fine to display 3434 3434.0.

3¡¢ i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.

´ð°¸ 3 µÚ 52Ìâ What is the value of the following expression?

true || true && false 1¡¢ true

2¡¢ false ´ð°¸ 1 µÚ 53Ìâ Which of the following statements are true? 1¡¢ (x > 0 && x < 10) is same as ((x > 0) && (x < 10))

2¡¢ (x > 0 || x < 10) is same as ((x > 0) || (x < 10))

3¡¢ (x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 && y < 0)) 4¡¢ (x > 0 || x < 10 && y < 0) is same as ((x > 0 || x < 10) && y < 0) ´ð°¸ 1 2 3 µÚ 54Ìâ How many times will the following code print \ int count = 0; while (count < 10) {

System.out.println(\count++; } 1¡¢ 8 2¡¢ 9 3¡¢ 10

4¡¢ 11 5¡¢ 0 ´ð°¸ 3 µÚ 55Ìâ Analyze the following code. int count = 0; while (count < 100) { // Point A

System.out.println(\count++; // Point B }

// Point C

1¡¢ count < 100 is always true at Point A 2¡¢ count < 100 is always true at Point B 3¡¢ count < 100 is always false at Point B

4¡¢ count < 100 is always true at Point C 5¡¢ count < 100 is always false at Point C ´ð°¸ 1 5 µÚ 56Ìâ How many times will the following code print \ int count = 0; do {

System.out.println(\ } while (count++ < 10); 1¡¢ 8 2¡¢ 9 3¡¢ 10

to

Java!\

to

Java\

4¡¢ 11 5¡¢ 0 ´ð°¸ 4 µÚ 57Ìâ What is the value in count after the following loop is executed? int count = 0; do {

System.out.println(\ } while (count++ < 9); System.out.println(count); 1¡¢ 8 2¡¢ 9 3¡¢ 10

4¡¢ 11 5¡¢ 0 ´ð°¸ 3 µÚ 58Ìâ Do the following two statements in (I) and (II) result in the same value in sum? (I): for (int i = 0; i<10; ++i) { sum += i;

} (II): for (int i = 0; i<10; i++) { sum += i; }

1¡¢ Yes 2¡¢ No ´ð°¸ 1 µÚ 59Ìâ Is the following loop correct? for (; ; ); 1¡¢ Yes 2¡¢ No ´ð°¸ 1 µÚ 60Ìâ Analyze the following code: public class Test { public static void main (String args[]) { int i = 0; for

(i

=

0;

i

<

10;

i++);

System.out.println(i + 4); } }

1¡¢ The program has a compile error because of the semicolon (;) on the for loop line.

2¡¢ The program compiles despite the semicolon (;) on the for loop line, and displays 4.

3¡¢ The program compiles despite the semicolon (;) on the for loop line, and displays 14.

4¡¢ The for loop in this program is same as for (i = 0; i < 10; i++) { }; System.out.println(i + 4); ´ð°¸ 3 4

µÚ 61Ìâ To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy?

1¡¢ add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0.

2¡¢ add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable whose initial value is 0.

´ð°¸ 1 µÚ 62Ìâ What is sum after the following loop terminates? int sum = 0; int item = 0; do { item++; sum += item; if (sum > 4) break;

} while (item < 5); 1¡¢ 5 2¡¢ 6

3¡¢ 7 4¡¢ 8 ´ð°¸ 2 µÚ 63Ìâ After the continue outer statement is executed in the following loop, which statement is executed? outer: for (int i = 1; i < 10; i++) { inner:

for (int j = 1; j < 10; j++) { if (i * j > 50) continue outer; System.out.println(i * j); } } next:

1¡¢ The control is in the outer loop, and the next iteration of the outer loop is executed.

2¡¢ The control is in the inner loop, and the next iteration of the inner loop is executed.

3¡¢ The statement labeled next.

4¡¢ The program terminates. ´ð°¸ 1 µÚ 64Ìâ Suppose the input for number is 9. What is the output from running the following program? import java.util.Scanner; public class Test {