0

Why would I want to place the increment sign after the value if it would give the same vlaue

Int x=1; System.out.println(x++) Output: 1

24th Jul 2017, 8:48 PM
Ishaq Za'rour
7 Answers
+ 3
x++ means use the value of x and then increment ++x means first increment it and then use it. eg int x=1 System.out.print(x++);// output 1 System.out.print(x);// output 2 and int x=1 System.out.print(++x);// output 2 System.out.print(x);// output 2
24th Jul 2017, 9:08 PM
Devbrath
Devbrath - avatar
+ 3
It increments the value of x by 1, but it does that after it prints it. If you want to increment it first and then print it you should use: System.out.println(++x);
24th Jul 2017, 8:52 PM
ChessMaster
ChessMaster - avatar
+ 2
heres your 2 😅 int x=1; System.out.println(x++ + --x);
24th Jul 2017, 9:11 PM
D_Stark
D_Stark - avatar
+ 1
im guessing this would be more useful in a loop
24th Jul 2017, 8:56 PM
D_Stark
D_Stark - avatar
0
OK what I mean why would I add the increment sign after x if It won't do anything useless
24th Jul 2017, 8:56 PM
Ishaq Za'rour
0
Well in a loop ++x is as same as x++ But without a loop ++x adds 1 to the value but x++ adds then removes a 1 from the value so the value would be the same
24th Jul 2017, 9:00 PM
Ishaq Za'rour
0
Ohh
24th Jul 2017, 9:13 PM
Ishaq Za'rour