++i is different from i++ and similarly --i is different from i--
lets watch this with an example
package Example1;
public class IncrementOrDecrement {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x=10;
System.out.println(x++);first display x value and then increment so now x is 11
System.out.println(++x);first it increments which would be 12 and then display
}
}
output:10
12
package Example1;
public class IncrementOrDecrement {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x=10;
System.out.println(x--);first display x value and then decrement so now x is 9
System.out.println(--x);first it decrements which would be 8 and then display
}
}
output:10
8
>>>Math functions
------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment