This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes OP= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OP=" Watch "OP=" New topic
Author

OP=

Buddhi Vikasitha
Greenhorn

Joined: Nov 01, 2012
Posts: 17



I'm confused with this operational assignment and I need to know how will this one execute and what will the result be? Beginner... thanks.
Stuie Clarky
Ranch Hand

Joined: Nov 09, 2012
Posts: 72

+= adds the right variable to the left variable, and stores the result in the left variable, e.g a=1, b=2, a+=b would result in a=3. The * works in a similar fashion, except it multiples instead. In this example you can follow it through in your head and then see if what you get is the same as what the output of 'a' is.


OCAJP 7
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3967
    
  17

Buddhi Vikasitha wrote:I need to know how will this one execute and what will the result be? Beginner... thanks.


Wheras Stuie gave you the basics on how the operators work, your question is a bit more complicated because of the type conversions. The best way to see how it executes and what the result will be would be to run it. What do you get? Then try to break the key line:

into smaller sequential parts to see if you can find out what each step does.


Steve
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18133
    
  39

Steve Luke wrote:
Wheras Stuie gave you the basics on how the operators work, your question is a bit more complicated because of the type conversions. The best way to see how it executes and what the result will be would be to run it. What do you get? Then try to break the key line:

into smaller sequential parts to see if you can find out what each step does.



Also, it may help to know that all compound assignment operators have the same precedence -- and have right to left associativity.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OP=
 
Similar Threads
polymorphism and casting question logic
Dan's Operator C Exam
New Mock Exam questions...
Strings
<<<EOF in javascript?