First of all, my mother language is not English.
Now I study Increment(++) ande Decrement(–) operators of Java.
I tried an issue. But the result of mu code differents from my expectation.
Issue
- Assign an integer to x.
- Using Increment(++) ande Decrement(–) operators and showing x.
My code
I wrotea code like this ;
public class Main{
public static void main(String[] args){
int x = 19;
int inc = x++;
int dec = x--;
System.out.println(inc);
System.out.println(dec);
}
}
My Expectation
I expected the result will be “20” and “19”.
Result
However, running result was “19” and “20”.
I still can’t understand why the result was “19” and “20”.
The thing I want to know
- Why the result of running my code was “19” and “20”.
- If the result of running my code will be “20” and “19”, where should I fix my code?