




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
AP Computer Science A Final COMPLETE EXAM LATEST VERSION 2026-2027 QUESTIONS AND 100% Verified ANSWERS.pdf
Typology: Exams
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















Which of the following can be used to replace /* missing code */ so that between will hold the correct value. - answer>>>(x >= lower) && (x <= upper);
Consider the following variables that appear in a program representing student information.
int assignmentsCompleted;
double testAverage; boolean
isPassing;
A student can pass a programming course if at least one of the following conditions is met.
The student has a test average that is greater than or equal to 90. The student has a test average that is greater than or equal to 75 and has at least 4 completed assignments.
Consider the following proposed implementations of the conditions.
I. if (testAverage >= 90) isPassing = true;
else if (testAverage >= 75 && assignmentsCompleted >= 4)
isPassing = true; elseisPassing = false;
II. boolean pass = false; if (testAverage >= 90) pass = true; else if (testAverage >= 75 && assignmentsCompleted
= 4) pass = true; isPassing = pass;
III. isPassing = (testAverage >= 90) || (testAverage >= 75 && assignmentsCompleted >= 4);
Which of the implementations will work correctly - answer>>>I, II, and III
State what's printed: int
a = 84, b = 1; boolean tf
= true;
System.out.println((a != 1) || tf || (a == b)); - answer>>>True
What is output by the following code?
int a = 90, b = 8; if(
(a<b) || (a-12>b) ) a
= b;
System.out.println(b++); - answer>>>
A teacher put three bonus questions on a test and awarded 5 extra points to anyone who answered all bonus questions correctly and no extra points otherwise. Assume that the boolean variables bonusOne, bonusTwo, and bonusThree indicate whether a student has answered the particular question correctly. Each variable was assigned true if the answer was correct and false if the answer was incorrect.
Which of the following code segments will properly update the variable grade based on a
student's performance on the bonus questions?
I. if (bonusOne && bonusTwo && bonusThree) grade += 5;
range");III. if (value >= 0)System.out.print("In range"); else if (value <= 100)System.out.print("In range");elseSystem.out.print("Not in range");
Which of the replacements will have the same behavior as the original version of the code segment? - answer>>>II only
Assume that a, b, and c are variables of type int. Consider the following three conditions.
I. (a == b) && (a == c) && (b == c)II. (a == b) || (a == c) || (b == c)III. ((a - b) * (a - c) * (b - c)) == 0
Assume that subtraction and multiplication never overflow. Which of the conditions above is (are) always true if at least two of a, b, and c are equal? - answer>>>
What are the final values of a, b, and c?
int a = 4, b = -9, c = 7;if (a > b && b > c) if (b < a) b = -b; else a = -a;else if (a > b || b > c) if (a < c) c = -c; else if (! (c > b)) b = -a; - answer>>>a= 4, b= -9, c= -
Consider the following code.
if (value < 0 || value > 100)System.out.println("true");elseSystem.out.println("false"); Given that value is an integer, which of the following code segments would have the same output as the code above?
I. if (value < 0){if (value > 100)System.out.println("true");elseSystem.out.println("false");}elseSystem.out.println("fa lse");II. if (value < 0)System.out.println("true");else if (value > 100)System.out.println("true");elseSystem.out.println("false");III. if (value >= 0)System.out.println("false");else if (value <= 100)System.out.println("false");elseSystem.out.println("true"); - answer>>>II only (check this)
What are the final values of a, b, and c?
int a = 4, b = 9, c = -3;if (a >= b) if (c < b) a = b + c; else c = a - c;else if (c < a) b = c - b; - answer>>>a= 4, b= -12, c= -
Consider the following code segment.
int result= 99;if (num1 == num2) {result = 0:}else if (num1 > num2) {result = 1;}else {result = -1;}System.out.println(result);
Which of the following code segments will print the same result as the code above no matter what integers are stored in num1 and num2?
I.int result = 99;if (num1 == num2) {result = 0;}else {if (num1 > num2) {result = 1;}else {result = -1;}}System.out.println(result);II.int result = 99;if (num1 == num2) {result = 0;}if (num1 >= num2) {result = 1;}else {result = -1;}System.out.println(result); III.int result = 99;if (num1 == num2) {result = 0;}if (num1 > num2) {result = 1;}if (num1 < num2) {result = -1;}System.out.println(result); - answer>>>I and III
Consider the following code segment.
int x = /* some integer greater than zero */int n = 100;if (x < 1000){ if (x > 1000) n = 200; else n = 300;}else{ if (x < 1000) n = 400; else n = 300;}System.out.println(n);
What is printed as a result of executing the code segment? - answer>>>
Show the basic skeleton of an if - else structure. - answer>>>if( )
{
}
else
{
}
What is output by the following?
int x = 8, y = 5;if( !(x == y) ){ System.out.println("Sunday, Monday");}else{ System.out.println("Happy Days!");} - answer>>>Sunday, Monday
What is the data type of the following literal?
"B" - answer>>>String (s uppercase)
What is the camel case variable name for a variable that represents the last score? - answer>>>lastScore
Which of the following is a keyword? - answer>>>boolean
Which of the following is NOT the name of a Java primitive data type? - answer>>>String
What data type would you use to store this number?
189.24 - answer>>>double
What data type should you use to record if it is raining or not? - answer>>>boolean
What is the data type of the following literal?
"fooled you" - answer>>>String
Which of the following is equivalent to
!(a && (c < d)) - answer>>>!a || (c >= d)
Consider the following declarations.
int valueOne, valueTwo;
Assume that valueOne and valueTwo have been initialized. Which of the following evaluates to true if valueOne and valueTwo contain the same value? - answer>>>valueOne == valueTwo
The boolean expression
!(A || B) evaluates to - answer>>>true whenever both A is false and
B is false.
State what's printed:
int a = 84, a= 1;boolean tf = true;System.out.println(tf && !tf); - answer>>>false
Consider the following code segment which is intended to assign true to between if x is between lower and upper, inclusive, and false otherwise. Assume lower <= upper and all values have been initialized.
int x;int lower;int upper;boolean between;boolean = /missing code/ - answer>>>(x >= lower) && (x <= upper);
Consider the following variables that appear in a program representing student information.
int assignmentsCompleted;double testAverage;boolean isPassing;
A student can pass a programming course if at least one of the following conditions is met.
The student has a test average that is greater than or equal to 90.
The student has a test average that is greater than or equal to 75 and has at least 4 completed assignments.
Consider the following proposed implementations of the conditions.
I. if (testAverage >= 90)isPassing = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)isPassing = true;elseisPassing = false;II. boolean pass = false;if (testAverage >= 90)pass = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)pass = true;isPassing = pass;III. isPassing = (testAverage >=
Consider the following code segment. Assume value is an int.
if (value < 0) || value < 100)System.out.print("Not in range");elseSystem.out.print("In range");
Consider the following code segments that could be used to replace the code.
I. if (value < 0){if (value > 100)System.out.print("Not in range"); elseSystem.out.print("In range");}elseSystem.out.print("In range");II. if (value < 0)System.out.print("Not in range"); else if (value < 100)System.out.print("Not in range");elseSystem.out.print("In range");III. if (value >= 0)System.out.print("In range"); else if (value <= 100)System.out.print("In range");elseSystem.out.print("Not in range");
Which of the replacements will have the same behavior as the original version of the code segment? - answer>>>II only
Consider the following code segment.
int result= 99;if (num1 == num2) {result = 0:}else if (num1 > num2) {result = 1;}else {result = -1;}System.out.println(result);
Which of the following code segments will print the same result as the code above no matter what integers are stored in num1 and num2?
I.int result = 99;if (num1 == num2) {result = 0;}else {if (num1 > num2) {result = 1;}else {result = -1;}}System.out.println(result);II.int result = 99;if (num1 == num2) {result = 0;}if (num1 >= num2) {result = 1;}else {result = -1;}System.out.println(result); III.int result = 99;if (num1 == num2) {result = 0;}if (num1 > num2) {result = 1;}if (num1 < num2) {result = -1;}System.out.println(result); - answer>>>I and III
int x = /* some integer greater than zero */int n = 100;if (x < 1000){ if (x > 1000) n = 200; else n = 300;}else{ if (x < 1000) n = 400; else n = 300;}System.out.println(n);
What is printed as a result of executing the code segment? - answer>>>
int x = 8, y = 5;if( !(x == y) ){ System.out.println("Sunday, Monday");}else{ System.out.println("Happy Days!");} - answer>>>Sunday, Monday
Consider the following code segment.
int n =
What is the value of count when the code finishes executing? - answer>>>(n - 1)^
Consider the following code segment.
for (int outer = 0; outer < n; outer++){ for (int inner = 0; inner <= outer; inner++) { System.out.print(outer + " "); }}
If n has been declared as an integer with the value 4, what is printed as a result of executing the code segment? - answer>>>0 1 1 2 2 2 3 3 3 3
Consider the following code segment
for(int i = 0; i <= 3; i++){for(int j = 1; j <=5; j+=2){System.out.println("*");}}
How many times will a '*' be printed? - answer>>>
Consider the following output.
1
1
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1Which of the following code segments will produce the output shown above? - answer>>>for (int j = 1; j <= 6; j++){ for (int k = 1; k <= j; k++) System.out.print(" " + k); System.out.println();}
Consider the following code segment.
String str = "012345";for (int i = 0; i < str.length() - 1; i++){ System.out.print(str.substring(i, i+2));}
What is printed as a result of executing this code segment? - answer>>>
Consider the following code segment.
for (int k = 0; k < 20; k = k + 1){ if (k % 2 == 1) System.out.print((k + 1) + " ");}
What is printed as a result of executing the code segment? - answer>>>2 4 6 8 10 12 14 16 18
Sometimes, a for loop's "initialization" statement may be empty, as in int i = keyboard.readInt(); for ( ; i < n; i++) ... - answer>>>True
Consider the following code segments.
I. int k = 1; while (k < 20) { if (k % 3 == 1) System.out.print(k + " "); k = k + 3; }II. for (int k = 1; k < 20; k = k + 3) { if (k % 3 == 1) System.out.print(k + " "); }III. for (int k = 1; k < 20; k = k
Which of the code segments above will produce the following output? 1
4 7 10 13 16 19 - answer>>>I, II, and III
What is the value of the int variable d after the following statement is executed?
for (d = 1; d < 567; d *= 10); - answer>>>
Consider the following code segment.
String s1 = "MADAM";String s2 = "";for (int k = 0; k < s1.length(); k++){ s2 += s1.substring(k); s2 += " ";}System.out.println(s2); - answer>>>MADAM ADAM DAM AM M The following statements display 21 instead of the expected 121. Why?
int m, q = 1, sum = 0;for (m = 0; m <= 10; m++)q = 2 * m + 1;sum += q;System.out.println(sum); - answer>>>Missing Braces
for(int i = 9; i < 11; i +=2){ System.out.println(i + ",");}
What is the step expression? - answer>>>i += 2
Consider the following code segment.
for (int k = 1; k <= 100; k++){ int n1 = (int) Math.random() * 2; int n2 = (int) Math.random() * 2; boolean boo1 = n1 == n2; System.out.print(boo1 + " ");}
What is printed as a result of executing the code segment? - answer>>>The code segment always prints true.
What is the value of sum after the following code fragment is executed?
int sum = 0, x = 1;while (sum < 20 && x <= 5){ sum += 2 * x; x++;} - answer>>>
Consider the following code segment.
int p = 10;int q = 5;while (q != 0 && p/q > 0){ p--;System.out.println(p + " " + q); q--;} What
is the last output when the segment executes? - answer>>>5 1
Consider the following code segment. int sum = 0;int k = 1;while (sum < 12 || k
< 4) sum += k;System.out.println(sum);
What is printed as a result of executing the code segment? - answer>>>Nothing is printed due to an infinite loop.
Consider the following code segment.
int num = 2574;int result = 0;while (num > 0){ result = result * 10 + num % 10; num /= 10;}System.out.println(result);
What is printed as a result of executing the code segment? - answer>>>
Which of the following best describes why this method does not compile? - answer>>>It is possible to reach the end of the method without returning a value.
Consider the following method.
/** Precondition: p > 0 */public static int method0201(int p){ int count = 1; for (int q = 1; q < p; q++) { count += count; } return count;}
What value is returned as a result of the fall method0201(n)? - answer>>>2^(n - 1)
Consider the following two methods.
/** Precondition: n1 > 0 * n2 > 0 /public static int method0207a(int n1, int n2){ int temp = method0207b(n1, n2); return n1 / temp * n2;}/* Precondition: p > 0 * q > 0 */public static int method0207b(int p, int q){ int rem = 1; int k = 0; while (rem != 0) { rem = p % q; if (rem == 0) { k = q; } else { p = q; q = rem; } } return k;}
What value is returned as a result of the call method0207a(30, 45)? - answer>>>
Consider the following code segment and class.
Student mack = new Student(11);System.out.println(mack.getAge());public class Student{ private int age;public Student(int a) { age = age; } public int getAge() { return age; }} What is printed as a result of executing the code segment? - answer>>>
Consider the following static method.
public static int calculate(int x){ x = x + x; x = x + x; x = x + x; return x;}
Which of the following can be used to replace the body of the calculate so that the modified version of calculate will return the same result as the original version for all x? - answer>>>return 8 * x;
Consider the following code segment and class.
Widget w1 = new Widget(66);Widget w2 = new Widget(77);System.out.println(w1.getWidgets() + " " +
w2.getWidgets());System.out.println(w1 + " " + w2);public class Widget{ private int numWidgets; public Widget(int numWidgets) { numWidgets = numWidgets; } public int getWidgets() { return numWidgets; }} - answer>>>0 0
Widget@112383b3 Widget@1a9a8e
Consider the following code segment and class.
Student mack = new Student();System.out.println(mack.getAge());public class Student{ private int age; public int getAge() { return age; }}
What is printed as a result of executing the code segment? - answer>>>
Consider the following program.
public class DS0210{public static void main(String args[]) { samba(65.0);}public static void samba(int k) { System.out.println(k);}public static void samba(double k) { System.out.println(k);}public static void samba(char k) { System.out.println(k);} public static void samba(String k) { System.out.println(k);}}
What is printed as a result of executing the program? - answer>>>65.
Consider the following method.
public void numberCheck(int maxNum){ int typeA = 0; int typeB = 0; int typeC = 0; for (int k = 1; k <= maxNum; k++) { if (k % 2 == 0 && k % 5 == 0) typeA++; if (k % 2 == 0) typeB++; if (k % 5 == 0) typeC++; } System.out.println(typeA + " " + typeB + " " + typeC)}
What is printed as a result of the call numberCheck(50)? - answer>>>5 25 10
Consider the following code segment and method.
int x = 5;x = method0205(x);System.out.println(x);public static int method0205(int n){ for (int k = n; k <= 10; k++) n += k; return n;}
What is printed as a result of executing the code segment? - answer>>>
Examine this code:
The boolean expression (A || B) || !(A ||
B) evaluates to - answer>>>true in all
cases.
The following table shows several examples of input and output values.
Input value Output value
3 30
6 60 7 7 8 80 9 90 11 11 12 120
14 14
16 160
Which of the following code segments could be used to produce the output values using the input values for n?
I. if ((n % 3 == 0) && (n % 4 == 0))System.out.println(n * 10);elseSystem.out.println(n);II. if ((n % 3 == 0) || (n % 4 == 0))System.out.println(n * 10);elseSystem.out.println(n);III. if (n % 3 == 0)if (n % 4 == 0)System.out.println(n * 10);elseSystem.out.println(n); - answer>>>II only
Consider the following method.
if ((a < 0) && (b > 0)){if (a > b)System.out.println("A");elseSystem.out.println("B");}else if ((b < 0) || (a < 0))System.out.println("C");elseSystem.out.println("D");
What is printed if a = 3 and b = -2? - answer>>>C
What are the two possible values for a boolean variable? - answer>>>true and false
Determine the output of the following code segments. Write no output if there is no output. int i = 2; int j = 3; if (j != i) { System.out.println ("You got it!"); } - answer>>>You got it!
In an if statement the condition is called the - answer>>>boolean expression
What is the value of a, b, and c after the following code segment?
int a = 45;int b = 10;int c = a % b;if (c != 0){ a = b; b = c;} - answer>>>a = 10, b = 5, c = 5
Consider the following code segment.
int num = 2574;int result = 0;while (num > 0){ result = result * 10 + num % 10; num /= 10;}System.out.println(result);
What is printed as a result of executing the code segment?
Correct answer: - answer>>>
Consider the following code segment.
int k = 1;while (k < 20){ if ((k %3) == 1) System.out.print(k + " "); k++;}
What is printed as a result of executing this code segment? - answer>>>1 4 7 10 13 16 19 What is the value of sum after the following code fragment is executed?
int sum = 0, x = 1;while (sum < 10 && x <= 5){ sum += 2 * x; x++;} - answer>>>
Consider the following code segment.
int k = 0;while (k < 10){ System.out.print((k % 3) + " "); if ((k % 3) == 0) k = k + 2; else k++;}
What is printed as a result of executing the code segment? - answer>>>0 2 0 2 0 2 0