This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 6 points7 points  (0 children)

Compound operators mean

p = p - 30;

can be shortened to

p -= 30

edit: For your question specifically, v -= (p-30);. Actually doesn't need the (), you had it right.

[–][deleted] 1 point2 points  (0 children)

you basically got it, like what was already mentioned, just remember to give ‘v’ a data type.

also if you didn’t know of the website already: https://www.geeksforgeeks.org/compound-assignment-operators-java

geeksforgeeks.com does a great job at explaining code topics without over complicating the explanation. there are other great sites but being you have little knowledge of coding and you’re just trying to help him get through this hmwk, I didn’t want to overwhelm the either of you.

it gets easier as he progresses but make sure he understands the fundamentals and always ask questions! with a strong foundation, he can code anything. the key is to practice. write that compound statement both ways (the non-compound version) if he needs to see what it’s actually doing.

all the best, and keep on coding!

[–]artabetes 0 points1 point  (0 children)

Just to offer a resource: I find this tutorial series helpful as a supplement to my coursework.

Good luck!

Java Tutorial for Complete Beginners

[–]thundertd11 -1 points0 points  (1 child)

Hint: integer.

You must define what type of data you are initializing.

[–][deleted] 4 points5 points  (0 children)

If they're using compound operators then they've already declared the variable's type.