+ 2

What will be the output?

int m = 7, n = 4, p = 2; System.out.println (m -= m/n + (p--) * (p++) ); Please explain it in steps.

30th Nov 2017, 3:42 AM
Gammaburst
Gammaburst - avatar
4 Antworten
+ 2
m-=expression <=> m = m - (expression) there is expression = m/n+(p--)*(p++)
1st Dec 2017, 6:08 AM
abdulazizumarovich
abdulazizumarovich - avatar
+ 2
m=7 n=4 p=2 m = m - ( m/n + (p--)*(p++)) m/n = 7/4 = 1 p-- =(used: 2)(saved to memory: 1) p++ =(used: 1)(saved to memory: 2) m = 7- ( 1 + 2*1) = 4 output: 4
30th Nov 2017, 5:29 AM
abdulazizumarovich
abdulazizumarovich - avatar
+ 2
Abdulaziz, can you please explain why did you put "m/n+(p--)*(p++)" in parenthesis? Does the compiler do that? If yes, why? Thanks for the time and help :D
1st Dec 2017, 1:19 AM
Gammaburst
Gammaburst - avatar
+ 1
Got it! Thanks, Abdulaziz :)
2nd Dec 2017, 3:05 AM
Gammaburst
Gammaburst - avatar