+ 1
Shorthand operator is giving different result
i=i-j and i-=j both are giving different results. Why this is happening?
13 ответов
+ 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 ...
+ 3
For the sake of clarity, please share the code's link 👍
+ 2
It result same.
May you have doing something wrongly.. Chech again..
+ 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 .
+ 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).
+ 1
R_N No. Am getting same output..
Add what input you are giving and what you getting as output?
+ 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
+ 1
Jayakrishna🇮🇳
Thanks! You are right. Got the answer.
0
I have a problem that i can't solve alone anyone to help
0
shortHand just & just is meant to compile cods faster.
0
Hi Can i talk to you
0
sure