+ 1
What is the conclusion of this code?
class A{ Public static void main(String [] array){ int val1=1; int val2=1; int result1=val1+++val1; int result2=++val2+val2; System.out.println(result1==result2); } }
7 Answers
+ 28
i know its val1+++val1 , i am telling that it will be written as val1++ + val1 , not val1 + ++val1 , it would not be possible to explain that using 1 variable only ... as it will give same output if we think in any way with 1 variable "val1"
//yes , its not a challenge question , but in most challenge it is used âș
+ 27
see this âșđ
//& yes, make P of Public small
https://www.sololearn.com/Discuss/995934/?ref=app
+ 27
val1+++val2 is val1 + ++val2 or val1++ + val2
//might need to see operator precedence
so it will be val1++ + val2
so 3 and 4
+ 7
What val1+++val1 does is it increments just the val1 by 1 and adds it to val1 (as it being a postfix increment, the value of first val1 is still taken as 1 and the result1 leads to 3).
Result2 instead, leads to 4 (which causes the comparison to return false).
+ 7
@Gaurav: Unexpectedly, his code is a little different. It's val1+++val1; I hope it's not a challenge question :D
+ 6
@Burcu: Actually, you must spell the access modifier "public" with a lowercased p. Only then you get the output as false as stated by @Muhammad Khairul Amirin Bin Yaacob
+ 5
False -- I ran it in Code Playground