- 1

Wrong Question's Answer in a Challenge

My answer 353530 Q. What is the output of this code? int x=3; System.out.print(x++); System.out.print(++x); System.out.print(7*x); System.out.print(++x*x-1);

9th Apr 2020, 6:42 AM
Abhay
Abhay - avatar
4 Answers
+ 2
the output is 353535 System.out.println(x++) ; // print 3 and increment x to 4 System.out.println(++x); //increment x (x=4+1) and print it, 5 System.out.println(7*x); //7*5=35 System.out.println(++x*x-1); // ++x increment x to 6 (x=x+1=5+1=6) and multiply the result by itself: ++x*x-1= 6*6-1=36-1=35 so the output is 353535
9th Apr 2020, 7:13 AM
John Robotane
John Robotane - avatar
+ 2
Abhay x++ means post increment. It will first assign the value then increment by 1. ++x means pre increment. It will first increment the value by 1 then assign. So according to your problem as John Robotane explained.
9th Apr 2020, 7:32 AM
A͢J
A͢J - avatar
+ 1
Can you tell the question?
9th Apr 2020, 6:48 AM
A͢J
A͢J - avatar
- 1
Watch out
9th Apr 2020, 6:50 AM
Abhay
Abhay - avatar