+ 1

Shorthand operator is giving different result

i=i-j and i-=j both are giving different results. Why this is happening?

17th Nov 2020, 4:46 PM
R_N
13 Answers
+ 4
R_N Can you describe the purpose and goal of the code, briefly? and which line(s) were troubling you? I was actually expecting a saved code link, so we can refer to line numbers easily. Raw text code doesn't have line numbers obviously. (Edit) Some examples for input may also help ...
17th Nov 2020, 6:34 PM
Ipang
+ 3
For the sake of clarity, please share the code's link 👍
17th Nov 2020, 5:11 PM
Ipang
+ 2
It result same. May you have doing something wrongly.. Chech again..
17th Nov 2020, 9:38 PM
Jayakrishna 🇮🇳
+ 2
https://code.sololearn.com/cb644x1w1r03/?ref=app It's not possible. both will give same. NOTE - suppose a variable hold a number 5 if you do like this int num = 10; num -= 3; //Now the value of num changed System.out.println(num);// now num is 7 num = num - 3; //Now num is 7 not 10 and after it the num changes System.out.println(num); OUTPUT WILL BE - 7 4 These are different maybe this is your mistake .
18th Nov 2020, 2:14 PM
Priyanshi
Priyanshi - avatar
+ 2
R_N In the 2nd expressions of instruction I = i -el-1 ; it's short form is i -= (el+1) You may using i -= (el-1).
18th Nov 2020, 3:41 PM
Jayakrishna 🇮🇳
+ 1
R_N No. Am getting same output.. Add what input you are giving and what you getting as output?
18th Nov 2020, 1:10 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 Check for the input 1 2 3 2 5 7 9 11 13 Using shorthand operator the answer is 33 And normal assignment (i = i-el) is giving 20
18th Nov 2020, 1:18 PM
R_N
+ 1
Jayakrishna🇮🇳 Thanks! You are right. Got the answer.
18th Nov 2020, 3:47 PM
R_N
0
I have a problem that i can't solve alone anyone to help
18th Nov 2020, 8:59 PM
Chibright
Chibright - avatar
0
shortHand just & just is meant to compile cods faster.
18th Nov 2020, 9:52 PM
Ali shahgholi
Ali shahgholi - avatar
0
Hi Can i talk to you
19th Nov 2020, 1:30 AM
Up Re
Up Re - avatar
0
sure
19th Nov 2020, 8:24 AM
Ali shahgholi
Ali shahgholi - avatar