• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OP=

 
Buddhi Vikasitha
Greenhorn
Posts: 17
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 98
Eclipse IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+= 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.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21436
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic