Choose the best response to each question or statement. 1. In Java, the result o
ID: 665640 • Letter: C
Question
Choose the best response to each question or statement.
1. In Java, the result of 41 / 2 is
a. 0
b. 1
c. 19
d. 20
e. 21
f. None of the above
2. int age = 32; if ( age >= 33 ) { System.out.println( "apple" ); } else { System.out.println( "orange" ); } System.out.println( "beer" );
a. Apple
b. Apple beer
c. Orange beer
d. None of the above
3. The following for loop prints numbers in the from ________ through ________. for(int i = 0; i < 22; i++) { System.out.println( i ); }
a. 0 through 21
b. I through 21
c. None of the above
4. final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87; if (num1 <= MAX && num3 <= LIMIT) { System.out.println ("apple"); } System.out.println ("orange"); What prints?
a. Apple
b. Apple orange
c. Nothing
5. int iResult, num1 = 25, num2 = 40, num3 = 17, num4 = 5; int num5 = -14, num6 = -27; double dResult, val1 = 17.0, val2 = 12.78; String sResult, title = “Hello from Java"; dResult = val1/ num4; What does dResult equal?
a. 0
b. 1
c. 2
d. 3
e. none of the above
6. How many times does the following loop execute? int m = 0; while( m >= 10 ) { System.out.println( m ); }
a. 9
b. 11
c. 0
d. This is an infinite number
7. The keyword for declaring a 16 bit integer in Java is ___________.
8. int iResult, num1 = 25, num2 = 40, num3 = 17, num4 = 5; int num5 = -14, num6 = -27; double dResult, val1 = 17.0, val2 = 12.78; String sResult, title = “Hello from Java"; iResult = num4 / num3; What does iResult equal?
a. 0
b. 1
c. 2
d. 3
e. None of the above
9. Which of the following is not a primitive type in Java?
a. Float
b. Int
c. Long
d. String
e. All of the above are primitive types in Java
10. The operations of a class, i.e., behaviors, are also called ________.
11. int age = 42; if( age > 33 ) { System.out.print( "apple" ); } System.out.println( "orange" );
a. apple
b. apple orange
c. none of the above
12. final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87; if (num3 - 5 >= 2 * LIMIT) { System.out.println ("apple"); } else { System.out.println ("orange"); } System.out.println("grape"); What prints?
a. Apple
b. Orange
c. Grape
d. Orange grape
e. Nothing
13. final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87; if (num3 <= MAX) { System.out.println ("apple"); } What prints?
a. Apple
b. Nothing
14. The body of a while loop is executed until the loop condition becomes ________.
a. True
b. False
15. What does the following loop print?
for( int i = 1; i <= 10; i = i + 2 ) { System.out.println( i ); }
a. Even number 2 through 10
b. 1 through 10
c. 1 through 9
d. Odd numbers 1 through 9
16. When you use a while loop to compute the sum of several values, you should initialize the variables holding the sum to ________ .
a. 0
b. 1
c. None of the above
17. Assuming the for loop header for( i = 0; i <= 7; i++ ), and the variable i has been properly declared as an int, what will be value of i after we exit the loop?
a. 0
b. 7
c. 8
d. 9
e. I will be out of scope
18. In the instance variable declaration (i.e., field declaration) private int value;
a. private is the access modifier, int is the name of the instance variable, and value is the data type
b. private is the access modifier, int is the data type, and value is the name of the instance variable
c. private is the data type, int is the access modifier, and value is the name of the instance variable
19. The data type of the return value of the toString method is ________.
a. Boolean
b. String
c. Char
d. None of the above
20. To access the element at index i of an array named grades, we use ________.
a. Grades i
b. Grades [i]
c. Grades {i}
d. None of the above
21. If an array has n elements, then the last index is ________.
a. N
b. N-1
c. None of the above
Explanation / Answer
1. d
2. c
3. a
4. b
5. e
6. c
7. short
8. a
9. e
10. methods
11. b
12. d
13. b
14. b
15. d
16. a
17. c
18. b
19. b
20. b
21. b