Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- public class IncrementAndDecremementOp
- {
- public static void main(String[] args)
- {
- //just add a value to a current value
- //a 'Postfix' operator because it comes after the variable
- //prefix & postfix op example:
- int num = 4;
- //increment
- System.out.println("num is "+num);
- num ++;
- //means +1 to current value of num, now it is s5
- System.out.println(" num is now"+num);//num is 5
- //decrement
- num --;
- // means -1 to current value of num, now it is 4
- //a 'Postfix' operator because it comes after the variable
- //prefix & postfix op example:
- //postfix
- System.out.println("println first"+num++);// 5
- System.out.println("after println:"+num);//4
- //adds after it is printed not before
- //prefix
- System.out.println("println first "+ ++num);//5
- System.out.println(num);//5
- //adds one before printing
- int x = 5;
- int y = ++x+x--;
- // adds 1 to 5, so ++x = 6, now +x and x is 6 so it is 12, ?????
- System.out.println(y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement