SAT / PSAT
SAT / PSAT Prep
History & Social Science
AP World History AP US History AP European History AP Human Geography AP US Government & Politics AP Psychology AP Macroeconomics AP Microeconomics
English
AP English Language & Composition AP English Literature & Composition
Math & Computer Science
AP Calculus AB/BC AP Precalculus AP Statistics AP Computer Science A AP Computer Science Principles
Sciences
AP Biology AP Chemistry AP Environmental Science AP Physics 1 AP Physics 2
World Languages & Arts
AP Spanish Language AP Art History AP Music Theory Start studying →
Unit 1 · Using Objects & Methods Flashcards Cheat Sheet Essentials Visual Review MC Practice FRQ Practice

AP Computer Science A Unit 1 FRQ Practice

Practice a College Board-style free response question using String and Math methods. Write your Java, then reveal the model answer to see exactly what earns each point.

← Back to Unit 1 hub
Free Response Question · Unit 1 · Using Objects and Methods

A programmer is working with a String variable and the Math class. Assume the following declarations:

String word = "Programming";
double value = -7.5;

Answer each part using appropriate Java expressions and method calls. (No loops or if-statements are needed — this unit is about objects and methods.)

A
Write a Java expression that evaluates to the number of characters in word, and state its value.

✓ Model answer

The expression is word.length(), which returns 11 (the String "Programming" has 11 characters).

Why it scores: Calls the length() instance method on the String with the dot operator and correctly reports 11. Writing length as a field (word.length) instead of a method call would lose the point.
B
Write a Java expression using a String method that returns the substring "gram" from word. Explain the indices you used.

✓ Model answer

word.substring(3, 7). In "Programming", index 0 is 'P', so 'g' is at index 3, and substring returns characters from index 3 up to but not including index 7 (indices 3, 4, 5, 6) — giving "gram".

Why it scores: Uses substring(from, to) with correct 0-based indices and explains that the second index is exclusive. Off-by-one indices (e.g., substring(3, 6)) would lose credit.
C
Write a Java expression using a Math method that returns the absolute value of value, and one that raises 2 to the power 5.

✓ Model answer

Absolute value: Math.abs(value), which returns 7.5. Power: Math.pow(2, 5), which returns 32.0 (a double).

Why it scores: Calls the static Math methods with the class name and dot operator and correct arguments, and knows Math.pow returns a double. Forgetting the class name (abs(value)) or swapping the pow arguments would lose points.

How to score points on AP CSA free response