AP CSA 1.7 Debugging: Reading the Documentation Wrong

Unit 1: Using Objects and Methods · Lesson 1.7 · Debugging

Reading the Documentation Wrong

API and Libraries. This is not a blank editor: it is someone else's attempt. Find what is wrong, fix it, and submit to be graded against hidden test cases.

Why debugging is its own skill

A library method does exactly what its documentation says, which is rarely exactly what you assumed. Math.pow hands back a double even when both arguments look like whole numbers, and Math.max takes two arguments, not three.

What is wrong with it

  1. Math.pow returns a double, so printing it directly gives 8.0 where the spec asks for 8. Cast the result to int.
  2. The largest of three values is attempted with a single Math.max call given a nested comparison that returns a boolean. Use two nested Math.max calls instead.
  3. The absolute value line is correct.

The program reads

Three integers: a base, an exponent, and a third value.

The program should print

Three lines: the base raised to the exponent as a whole number, the absolute value of the third value, and the largest of the three inputs.

Worked examples

These show what the FIXED program should print. There are more cases you cannot see, and they use different values, so patching around just these numbers will fail.

Example 1 input
2 3 -5
Example 1 output
8
5
3
Example 2 input
5 2 100
Example 2 output
25
100
100

Your answer

Main.java

Input for the Run button

Run sends whatever is in the code box below, bugs and all, so you can see the crash or the wrong answer for yourself before you fix anything.


  

  

Stuck?

Hint 1

Math.pow is declared to take two doubles and return a double. Java widens your ints on the way in without complaint, and the answer comes back as 8.0 rather than 8. A cast to int is the whole fix.

Hint 2

Math.max compares exactly two values. To compare three, feed the result of one call into another: Math.max(Math.max(a, b), c). The starter simply ignores the third value.

Hint 3

When a library method surprises you, the fastest fix is to read its signature: what types does it take, and what type does it hand back? Both bugs here are answered by that question alone.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]