AP Computer Science Unit 1 – Test Review Practice Questions

Last Updated on August 9, 2024

AP Computer Science Unit 1 – Test Review Practice Questions. AP Computer Science Principles (CSP) UNIT 1 Review Practice Test 2024: College Board’s Advanced Placement® Program (AP®) Computer Science Principles (CSP) Unit 1: Exam Primitive Types You’ll face the fundamentals of Java, a programming language, as well as other foundational concepts for coding questions.

AP Computer Science Unit 1 – Test Review Practice Questions

Test Prep  AP Exam
Subject Computer Science Principles (CSP)
Total Questions  20
Questions Type Multiple-Choice
Unit Unit 1: Primitive Types

0

AP Computer Science Unit 1 - Test Review Practice Questions

AP Computer Science Unit 1 - Test Review
On The Real Exam: 2.5%–5% of exam score

1 / 20

Consider this code segment:

int x = 10, y = 0;
while (x > 5)
{
y = 3;
while (y < x)
{
y *= 2;
if (y % x == 1)
y += x;
}
x -= 3;
}
System.out.println(x + " " + y);

What will be output after execution of this code segment?

2 / 20

In Java, a variable of type int is represented internally as a 32-bit signed integer. Suppose that one bit stores the sign, and the other 31 bits store the magnitude of the number in base 2. In this scheme, what is the largest value that can be stored as type int?

3 / 20

A common use of hexadecimal numerals is to specify colors on web pages. Every color has a red, green, and blue component. In decimal notation, these are denoted with an ordered triple (x, y, z), where x, y, and z are the three components, each an int from 0 to 255. For example, a certain shade of red, whose red, green, and blue components are 238, 9, and 63, is represented as (238, 9, 63). In hexadecimal, a color is represented in the format #RRGGBB, where RR, GG, and BB are hex values for the red, green, and blue. Using this notation, the color (14, 20, 255) would be coded as #RRGGBB.

Which of the following hex codes represents the color (14, 20, 255)?

4 / 20

Suppose that base-2 (binary) numbers and base-16 (hexadecimal) numbers can be denoted with subscripts, as shown below:

2Ahex = 101010bin

Which is equal to 3Dhex?

5 / 20

The following fragment intends that a user will enter a list of positive integers at the keyboard and terminate the list with a sentinel:

int value = 0;
final int SENTINEL = -999;
while (value != SENTINEL)
{
//code to process value
...
value = IO.readInt(); //read user input
}

The fragment is not correct. Which is a true statement?

6 / 20

Given that n and count are both of type int, which statement is true about the following code segments?

  • I. for (count = 1; count <= n; count++) System.out.println(count);
  • II. count = 1; while (count <= n) { System.out.println(count); count++; }

7 / 20

In the following code segment, you may assume that a, b, and n are all type int.

if (a != b && n / (a - b) > 90)
{
/* statement 1 */
}
else
{
/* statement 2 */
}
/* statement 3 */

What will happen if a == b is false?

 

8 / 20

Given that a, b, and c are integers, consider the boolean expression

(a < b) || !((c == a * b) && (c < a))

Which of the following will guarantee that the expression is true?

9 / 20

Assume that a and b are integers. The boolean expression

!(a <= b) && (a * b > 0)

will always evaluate to true given that

10 / 20

Which of the following will evaluate to true only if boolean expressions A, B, and C are all false?

11 / 20

What values are stored in x and y after execution of the following program segment?

int x = 30, y = 40;
if (x >= 0)
{
if (x <= 100)
{
y = x * 3;
if (y < 50)
x /= 10;
}
else
y = x * 2;
}
else
y = -x;

12 / 20

What will the output be for the following poorly formatted program segment, if the input value for num is 22?

int num = call to a method that reads an integer;
if (num > 0)
if (num % 5 == 0)
System.out.println(num);
else
System.out.println(num + " is negative");

13 / 20

Let x be a variable of type double that is positive. A program contains the boolean expression

(Math.pow(x,0.5) == Math.sqrt(x))

Even though x^1/2 is mathematically equivalent to √x, the above expression returns the value false in a student’s program. Which of the following is the most likely reason?

14 / 20

Which is true of the following boolean expression, given that x is a variable of type double?

3.0 == x * (3.0 / x)

15 / 20

Suppose that addition and subtraction had higher precedence than multiplication and division. Then the expression

2 + 3 * 12 / 7 - 4 + 8

Would evaluate to which of the following?

16 / 20

What value is stored in result if

int result = 13 - 3 * 6 / 4 % 3;

 

17 / 20

Refer to the following code fragment:

double answer = 13 / 5;
System.out.println("13 / 5 = " + answer);

The output is 13 / 5 = 2.0. The programmer intends the output to be 13 / 5 = 2.6. Which of the following replacements for the first line of code will not fix the problem?

18 / 20

Consider the following code segment

if (n != 0 && x / n > 100)
statement1;
else
statement2;

If n is of type int and has a value of 0 when the segment is executed, what will happen?

19 / 20

What output will be produced by

System.out.print("\\* This is not\n a comment *\\");

20 / 20

Which of the following pairs of declarations will cause an error message?

I double x = 14.7;
int y = x;
II double x = 14.7;
int y = (int) x;
III int x = 14;
double y = x;

 

Your score is

 Test Review Practice Questions 

AP CSP Practice Test 2024 Study Guide [UPDATED]

 Full Practice Test 

Unit 1 of the AP Computer Science A course typically covers the fundamentals of programming, focusing on the following key concepts:

1. Variables and Data Types

  • Primitive Data Types: int, double, char, boolean
  • Declaration and Initialization: How to declare and initialize variables.
  • Type Conversion: Implicit and explicit casting between data types.

2. Operators

  • Arithmetic Operators: +, -, *, /, %
  • Relational Operators: ==, !=, <, >, <=, >=
  • Logical Operators: &&, ||, !
  • Assignment Operators: =, +=, -=, *=, /=, %=

3. Control Structures

  • Conditional Statements: if, else if, else, and nested conditions.
  • Switch Statements: Using switch for multi-way branching.
  • Loops: for, while, do-while loops and their usage.

4. Methods

  • Method Declaration: Syntax for defining methods.
  • Method Calls: How to call methods and pass parameters.
  • Return Values: Methods that return values vs. void methods.
  • Method Overloading: Creating multiple methods with the same name but different parameters.

5. Arrays

  • Declaration and Initialization: How to declare and initialize arrays.
  • Accessing Elements: Using indices to access array elements.
  • Array Length: Using the .length attribute.
  • Array Traversal: Iterating over arrays with loops.

6. Introduction to Object-Oriented Programming

  • Classes and Objects: Basic concepts of classes and creating objects.
  • Constructors: Special methods used to initialize objects.
  • Instance Variables and Methods: Defining and using instance variables and methods.
  • Encapsulation: Using access modifiers (public, private) to protect data.

7. Strings

  • String Methods: Common methods like .length(), .charAt(), .substring(), .indexOf(), .toLowerCase(), .toUpperCase().
  • String Concatenation: Using + operator and .concat() method.

8. Input and Output

  • Reading Input: Using Scanner class for input.
  • Printing Output: Using System.out.println() and System.out.print().

9. Basic Algorithms

  • Searching: Basic search algorithms like linear search.
  • Sorting: Introduction to sorting algorithms like bubble sort.

10. Debugging and Testing

  • Error Types: Syntax errors, runtime errors, and logical errors.
  • Testing: Writing and running test cases to ensure code correctness.

Disclaimer: The AP Computer Science is a registered trademark of the College Board and the National Merit Scholarship Corporation. This publication is not endorsed by or affiliated with the College Board or the National Merit Scholarship Corporation. All information provided is independent of and not officially sanctioned by these organizations.