AP CSA 1.6 Debugging: The Operator That Is Two Operators

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

The Operator That Is Two Operators

Compound Assignment Operators. 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

x =+ 1 compiles. It is not a typo the compiler will catch, because it is a perfectly ordinary assignment of positive one, and it silently replaces the value instead of adding to it. Two characters in the wrong order change accumulation into overwriting.

What is wrong with it

  1. The running total uses total =+ value, which assigns the value rather than adding it, so the total ends up holding only the last number. Change it to the compound operator that adds.
  2. The countdown uses count =- 1, which assigns negative one every time instead of subtracting. Change it to the compound operator that subtracts.
  3. The multiply-by-two line already uses a compound operator correctly. Use it as your model.

The program reads

Three integers.

The program should print

Three lines: the sum of the three values, the value 10 reduced by 1 three times, and the third value doubled.

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
1 2 3
Example 1 output
6
7
6
Example 2 input
10 20 30
Example 2 output
60
7
60

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

Read total =+ a as total = (+a). The plus is a unary sign on a, not part of the assignment. So the statement means "replace total with a", and after three of them total holds only c.

Hint 2

Similarly count =- 1 means count = (-1), which is why the countdown from 10 lands on -1 instead of 7 no matter how many times it runs.

Hint 3

The compound operator always has the symbol FIRST and the equals second: += and -=. If the equals comes first, you have written a plain assignment with a signed value.

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]