Posts

Showing posts with the label assignment operator

Increment and Decrement Operators in JAVA

Increment Operators :  An increment or decrement operator provides a more convenient and compact way to increase or decrease the value of a variable by one . For example, the statement x=x+1; can be simplified to ++x; Example: int test = 5; ++test; // test is now 6 Decrement Operators :  The decrement operator (--) is used to decrease the value of a variable by one. Example :  int test = 5; --test; // test is now 4 Prefix & Postfix : Two forms, prefix and postfix , may be used with both the increment and decrement operators. With prefix form, the operator appears before the operand, while in postfix form, the operator appears after the operand. Below is an explanation of how the two forms work: Prefix  : Increments the variable's value and uses the new value in the expression. Example of increment operator : int x = 34; int y = ++x; // y is 35 The value of x is first incremented to 35, and is then assigned to y, so the val...