AP CS Java Basics MCQs
AP CS Java Basics MCQs
Features
II.
III.
(A) None
(B) I only
(C) II only
(D) III only
(E) I and III only
(C)
(D)
(E)
3. Consider the following code segment.
double answer = 13 / 5;
System.out.println("13 / 5 = " + answer);
The output is
13 / 5 = 2.0
Which of the following replacements for the first line of code will
not fix the problem?
(A) double answer = (double) 13 / 5;
(B) double answer = 13 / (double) 5;
(C) double answer = 13.0 / 5;
(D) double answer = 13 / 5.0;
(E) double answer = (double) (13 / 5);
5. What value is stored in result if
int result = 13 - 3 * 6 / 4 % 3;
(A) −5
(B) 0
(C) 13
(D) −1
(E) 12
9. What will the output be for the following poorly formatted program
segment, if the input value for num is 22?
(A) 22
(B) 4
(C) 2 is negative
(D) 22 is negative
(E) Nothing will be output.
10. What values are stored in x and y after execution of the following
program segment?
(A) x = 30 y = 90
(B) x = 30 y = -30
(C) x = 30 y = 60
(D) x = 3 y = -3
(E) x = 30 y = 40
13. Given that a, b, and c are integers, consider the boolean expression
(a < b) || !((c == a * b) && (c < a))
14. In the following code segment, you may assume that a, b, and n are
all type int.
15. Given that n and count are both of type int, which statement is true
about the following code segments?
I.
II.
16. The following fragment intends that a user will enter a list of
positive integers at the keyboard and terminate the list with a
sentinel.
18. Which of the following values of num will result in valid having a
value of true?
(A) 6143
(B) 6144
(C) 6145
(D) 6146
(E) 6147
Age Category
65 or above Senior
From 18 to 64 inclusive Adult
Below 18 Child
II.
III.
(A) I only
(B) II only
(C) III only
(D) II and III only
(E) I, II, and III
(A)
(B)
(C)
(D)
(E)
22. Which of the following program fragments will produce this output?
(Ignore spacing.)
I.
II.
III.
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III
(A) I only
(B) II only
(C) III only
(D) II and III only
(E) I, II, and III