+ 1

Why 2 +, but only 1 - ?

Why do I have to put in (if x=5): "++x" in order to get x=6, but:"-x" in order to get x=4?

10th Dec 2017, 5:17 PM
Joshua
5 odpowiedzi
+ 10
You need to have two (-) as well, -x is a syntax error. I guess you need the explaination for the prefix increment, there are already a lot of similar questions asked about it. Please have a look : https://www.sololearn.com/discuss/407846/?ref=app
10th Dec 2017, 5:20 PM
Dev
Dev - avatar
+ 7
++x is pre increment which first increment the value by 1 then use so here by the first statement x=5//assigned 5 to x ++x=x+1=>5+1=6 so here x is 6 and if you want to get 4 then you have to do like this --x //which is pre decrement which decrease the value by 1 first then use it so x become 4 https://www.sololearn.com/discuss/489143/?ref=app
10th Dec 2017, 5:24 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Oh yes, thank you @ Gordie! There was a mistake in the tutorial 6/9 of Java basic concepts 😂
10th Dec 2017, 7:20 PM
Joshua
0
Sorry but it doesn't really help me here... Is it just the way things are, or is there a deeper meaning behind using 2 plus but only one minus? I do understand everything, but I just want to know the reason 😂
10th Dec 2017, 6:08 PM
Joshua