Advertisement
Guest User

Increment & Decrement

a guest
Jun 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. /**
  2. You can increase a numeric variable's value by 1 using the increment operator: ++
  3. */
  4.  
  5.     number++;
  6.  
  7. /**
  8. You can decrease a numeric value by using the decrement operator: --
  9. */
  10.  
  11.     number--;
  12.  
  13. /**
  14. These are "post" increment and decrement.
  15.  
  16. 1. The value stored in nunber is modified
  17. 2. The old value is returned
  18.  
  19. If we were to do:
  20. */
  21.  
  22.     int number = 5;
  23.     int otherNumber = number++;
  24.  
  25. /**
  26. otherNumber would contain the value 5, number would contain the value 6.
  27. The pre-increment and pre-decrement value return the new number:
  28. */
  29.  
  30.     int number = 5;
  31.     int otherNumber = ++number;
  32.     // now both variables will contain 6.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement