What is ++int in Java?
13,504
Solution 1
a = 5; b = ++a; // a = 6, b = 6
a = 5; b = a++; // a = 6, b = 5
Solution 2
int a=1;
System.out.println(a++);
prints "1"
int a=1;
System.out.println(++a);
prints "2"
Or maybe i don't understand your question.
Solution 3
++int
increments int by 1 before and int++
increments by one after
Related videos on Youtube
Author by
user1260584
Updated on June 04, 2022Comments
-
user1260584 almost 2 years
Possible Duplicate:
explain working of post and pre increment operator in Java
What is the difference between int++ and ++int?In Java, what is
++int
? What does it do? What does it mean?(Sorry, but I didn't ask the question correctly last time.)
-
Brendan Long about 12 yearsIt's exactly the same as the C++ answer you got in your other question..
-
paxdiablo about 12 yearsIn future, please search before posting a question.
-
Kirk Woll about 12 years@Brendan, mostly true, but any differences are fully elaborated here.
-
-
Sionide21 about 12 yearsOther way around:
a
is incremented after the assigment.b
uses the old value ofa