Skip to Content

Increment and Decrement Operators Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Increment and Decrement Operators Example
  3.         This example shows how to use Java increment operator (++) and decrement
  4.         (--) operator.
  5. */
  6.  
  7. public class IncrementDecrementOperatorExample {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 /*
  12.                  * Java increment operator ++ increases its operand's value by one
  13.                  * while decrement operator -- decreases its operand's value by
  14.                  * one as given below.
  15.                  */
  16.                  
  17.                  int i = 10;
  18.                  int j = 10;
  19.                  
  20.                  i++;
  21.                  j++;
  22.                  
  23.                  System.out.println("i = " + i);
  24.                  System.out.println("j = " + j);
  25.                  
  26.                  /*
  27.                   * Increment and decrement operators can be used in two ways,
  28.                   * postfix (as given in above example) and prefix.
  29.                   *
  30.                   * In normal use, both form behaves the same way. However, when they
  31.                   * are part of expression, there is difference between these
  32.                   * two forms.
  33.                   *
  34.                   * If prefix form is used, operand is incremented or decremented
  35.                   * before substituting its value.
  36.                   *
  37.                   * On the other hand, if postfix form is used,
  38.                   * operand's old value is used to evaluate the expression.
  39.                   *
  40.                   * Simple example would be,
  41.                   */
  42.                  
  43.                   /*
  44.                    * Here, value of i would be assigned to k and then its
  45.                    * incremented by one.
  46.                    */
  47.                   int k = i++;
  48.                  
  49.                   /*
  50.                    * Here, value of j would be incremented first and then
  51.                    * assigned to k.
  52.                    */
  53.                   int l = ++j;
  54.                  
  55.                   System.out.println("k = " + k);
  56.                   System.out.println("l = " + l);
  57.                  
  58.                  
  59.         }
  60.        
  61. }
  62.  
  63. /*
  64. Output would be
  65. i = 11
  66. j = 11
  67. k = 11
  68. l = 12
  69. */