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
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
+ 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);
+ 2
heres your 2 đ
int x=1;
System.out.println(x++ + --x);
+ 1
im guessing this would be more useful in a loop
0
OK what I mean why would I add the increment sign after x if It won't do anything useless
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
0
Ohh