# Operators

• December 10th, 2012, 12:45 AM
Skybear
Operators
I could use some help understanding operators. ++, --, +=, -=, *=, /=, and %=. There's something about them that I'm just not getting. I would really appreciate your assistance!
• December 10th, 2012, 03:29 AM
vigneshwaran
Re: Operators
those operators are used just immediate to any variables.
like
Code JAVA:

```k++; //k=k+1 but post increment ++k; //pre increment the value of k```
similarly all functions as.
• December 10th, 2012, 07:24 AM
Norm
Re: Operators
Quote:

something about them that I'm just not getting.
Please give some details on your problem. Take a look at the tutorial:
Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
• December 11th, 2012, 11:10 AM
Skybear
Re: Operators
Thanks for the help. Here is an excerpt from the book I'm reading about operators and which doesn't seem to be explained by the Oracle Java tutorial. This is where my confusion comes from:
-------------
int x = 10;
int y = 20;
What value is z assigned? The answer is 220. The third assignment increments
x to 11 and decrements y to 19, but in computing the value of z, it uses the new
value of x (++x) times the old value of y (y– –), which is 11 times 20, or 220.
--------------------
I understand that ++x equals 10+1, which is 11. But I don't understand how --y equals 20. Does --y mean "y minus a minus" or y subtracting (or minus) a minus? That's what is confusing me.
• December 11th, 2012, 11:40 AM
helloworld922
Re: Operators
-- means decrement (subtract 1).

There's no mathematical intuition or basis for why this is, this is just some idea that the designers decided a long time ago was nifty.
• December 11th, 2012, 12:34 PM
Skybear
Re: Operators
That's what I thought. But how is ++y different from y++? And --y from y--? I ask because in the example above, where int y=20, y-- should mean 20-1 = 19. But the book has the answer as being 20.

Thanks for answering my newbie questions.
• December 11th, 2012, 12:47 PM
Norm
Re: Operators
Google postfix operator for lots of discussions about how the operators work.
• December 11th, 2012, 12:53 PM
Skybear
Re: Operators
Thanks. I was entering Java and operators, but it never occurred to me to try just try that. Google is giving me a lot of C++ pages, so I'll look at those. Nice indeed! Thanks!