Skip to Content
Java How to Program, Early Objects, 11th Edition
book

Java How to Program, Early Objects, 11th Edition

by Paul J. Deitel, Harvey Deitel
June 2017
Beginner
1296 pages
69h 23m
English
Pearson
Content preview from Java How to Program, Early Objects, 11th Edition

4.12 Compound Assignment Operators

The compound assignment operators enable you to abbreviate assignment expressions. For example, you can abbreviate the statement

c = c + 3; // adds 3 to c

with the addition compound assignment operator, +=, as

c += 3; // adds 3 to c more concisely

The += operator adds the value of the expression on its right to the value of the variable on its left and stores the result in the variable on the left. Thus, the assignment expression c+=3 adds 3 to c. In general, statements like

variable = variable operator expression;

where operator is one of the binary operators +, -, *, / or % (or others we discuss later in the text) and the same variable name is used can be written in the form

variable operator=  expression ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17

Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17

Kishori Sharan, Adam L. Davis
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan

Publisher Resources

ISBN: 9780134751962