Return value in AP Computer Science A

In AP Computer Science A, a return value is the data a method sends back to the code that called it, using a return statement; its type must match the method's declared return type (like int, boolean, double, String, or an object), and methods declared void return nothing.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is the Return value?

A return value is what a method hands back when it finishes running. In Java, every method header declares a return type, and that's a promise. A method declared int averageSteps() must give back an int, a method declared boolean isValid(String str) must give back true or false, and a method declared void gives back nothing at all. The return statement is how the method keeps that promise. The moment Java hits return, the method stops and ships that value back to whoever called it.

Here's the mental model that makes it click. A method call is like ordering food. The arguments are your order, the method is the kitchen, and the return value is the plate that comes back to your table. Printing inside the method is the cook shouting your order out loud. The shout doesn't put food on your table. Only return does. The caller can then store the return value in a variable, use it in an expression, pass it to another method, or chain another method call onto it.

Why the Return value matters in AP Computer Science A

Return values run through almost the entire AP CSA course. In Unit 1 you use return values from expressions and Math methods. In Unit 2 you call non-void methods on objects (like str.length() or str.substring(1, 3)) and have to know what type comes back so you can actually use it. In Unit 5 you flip to the other side and write the methods yourself, which means choosing a return type and making sure every path through your code returns a value of that type. In Units 6 through 8, algorithms like linear search are defined by what they return, such as the index of a found element or -1 if it's missing.

On the exam, this is one of the most common silent point-killers. FRQ scoring guidelines consistently dock solutions that print a result instead of returning it, return the wrong type, or forget to return anything on some branch of an if-else. If you can read a method signature and immediately know what kind of value comes back and how the caller will use it, you're set up for every FRQ.

How the Return value connects across the course

Function / Method (Units 2 & 5)

A return value only exists because a method produces it. Unit 2 tests whether you can call a non-void method and use what comes back; Unit 5 tests whether you can write the method so the right value comes back. Same concept, viewed from the caller's side and the writer's side.

Data type (Unit 1)

The declared return type locks in what a method can give back. Return a double from a method declared int and you get a compile error. This is the same type-compatibility rule you learned for variable assignment in Unit 1, just applied to methods.

Output (Units 1 & 5)

Output via System.out.println displays text to a human and then it's gone. A return value goes back into the program where other code can use it. The exam loves testing whether you know these are not the same thing.

Linear Search Algorithm (Units 6-7)

Linear search is basically a return-value contract. It returns the index where the target was found, or -1 if it wasn't. That 'return a sentinel value when the search fails' pattern shows up constantly in array and ArrayList FRQs.

Is the Return value on the AP Computer Science A exam?

Multiple-choice questions hand you a method and ask what value a specific call returns, or ask which return statement correctly completes a method. Watch for traps where a return inside a loop exits too early, or where one branch of an if-else has no return at all.

On the free-response section, return values are everywhere. The 2018 FRQ had you work with a boolean isValid(String str) method that returns true for valid strings. The 2019 StepTracker FRQ required methods that return computed values like counts and averages. The 2021 ArrayResizer FRQ asked for a static method returning a boolean about a 2D array row. In all of these, you earn points by returning the correct value of the correct type. Printing the answer instead of returning it, or returning the wrong type, costs you. Also expect to use return values from one method inside another, like calling a helper method and using its boolean result in your loop condition.

The Return value vs Output (printing)

Printing with System.out.println displays a value on the console for a human to read, and the program can't use it afterward. A return value goes back to the calling code, where it can be stored, compared, or passed along. return total; and System.out.println(total); look similar but do completely different things, and writing the print version when the FRQ says 'returns' will lose you the point even if your math is perfect.

Key things to remember about the Return value

  • A return value is the data a method sends back to its caller via the return statement, and its type must match the method's declared return type.

  • A void method returns nothing, so you can't store or use its result; a non-void method always returns exactly one value.

  • Executing a return statement immediately ends the method, even if it's inside a loop, so a misplaced return can cut a loop short.

  • Returning a value and printing a value are different. FRQ scoring guidelines penalize printing when the method is supposed to return.

  • Every possible path through a non-void method must return a value, including every branch of an if-else, or the code won't compile.

  • Common return-value patterns on the exam include returning a boolean from a validity check, returning a count or average, and returning -1 when a search fails.

Frequently asked questions about the Return value

What is a return value in AP Computer Science A?

It's the data a Java method gives back to the code that called it, produced by a return statement. The value's type must match the method's declared return type, like int, boolean, double, String, or an object reference.

Is returning a value the same as printing it?

No. Printing displays a value to the console and the program can't touch it afterward, while returning sends the value back to the caller so it can be stored or used in expressions. FRQs that say a method 'returns' a value will not award credit for printing it instead.

What does a void method return?

Nothing. A void method performs an action (like modifying an object or printing) but produces no return value, so writing something like int x = someVoidMethod(); causes a compile error.

Can a method have more than one return statement?

Yes, and it's common. A method can have a return in each branch of an if-else, but only one return ever executes per call because the method ends the instant a return statement runs. Every path through a non-void method still needs to return something.

How do return values show up on AP CSA FRQs?

Constantly. The 2018 FRQ used a boolean isValid(String str) method, the 2019 StepTracker FRQ required methods returning counts and averages, and the 2021 ArrayResizer FRQ asked for a method returning a boolean about a 2D array row. You earn points by returning the right value of the right type.