0% found this document useful (0 votes)
527 views8 pages

Increment Decrement

The document discusses different types of operators in Java including increment/decrement, arithmetic, assignment, relational, logical, and comma operators. It provides examples of how each operator is used and the operations they perform. The increment operator increases a variable by 1 while the decrement operator decreases it by 1. Arithmetic operators perform math operations. Assignment operators assign values. Relational operators check relationships. Logical operators are used for condition checking and decision making.

Uploaded by

COD COD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
527 views8 pages

Increment Decrement

The document discusses different types of operators in Java including increment/decrement, arithmetic, assignment, relational, logical, and comma operators. It provides examples of how each operator is used and the operations they perform. The increment operator increases a variable by 1 while the decrement operator decreases it by 1. Arithmetic operators perform math operations. Assignment operators assign values. Relational operators check relationships. Logical operators are used for condition checking and decision making.

Uploaded by

COD COD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Increment and Decrement Operators

1. Increment Operators
The Increment Operator is used to increment the value of a variable in
an expression by one.

 Prefix Increment
In the Pre-Increment, value is increased by 1 first and then
used inside the expression.
 Postfix Increment
In the Post-Increment, value is first used inside the expression
and then increased by 1.

2. Decrement Operators
The Decrement Operators is used to decrement the value of a variable
in an expression by one.

 Prefix Decrement
In the Pre-Decrement, the value is first decreased by 1 and then
used inside the expression.
 Postfix Decrement
In the Post-Decrement, value is first used inside the expression
and then decreased by 1.

Increment ++ Increases the value by 1


Decrement -- Decreases the value by
1
PREFIX AND POSTFIX INCREMENT:

PREFIX AND POSTFIX DECREMENT:

JAVA OPERATORS
1. Arithmetic Operators
Arithmetic Operators are used to perform arithmetic operations such
as addition, substraction, multiplication, division and modolu operation on
variables and data.
Operator Operation
+ Addition
- Substraction
* Multiplication
/ Division
% Modolu Operation(Remainder after division)
++ Increment
-- Decrement

EXAMPLE:

OUTPUT:

2. Assignment Operators
Assigment Operators are used to assign a values to any variables in
Java.
Operator Example Equivalent to
= a = b; a = b;
+= a += b; a = a + b;
-= a -= b; a = a – b;
*= a *= b; a = a * b;
/= a /= b; a = a / b;
%= a %= b; a = a % b;
EXAMPLE:

OUTPUT:
3. Relational Operators
Relational Operators are used to check the relationship between
operands like equal to, greater than, less than etc. They only return two
results which is True or False.
Operators Description
== Is Equal to
> Greater than
< Less than
>= Greater than or Equal to
<= Less than or Equal to
!= Not Equal to
EXAMPLE:
OUTPUT:

4. Logical Operators
Logical Operators are used in decision making and used to check
whether an expression is true or false.
Operator Example Meaning
&&(Logical AND) expression1 && expression2 true only if two expression1
and expression2 are true
||(Logical OR) expression1 || expression2 true if either expression1 and
expression2 is true
!(Logical NOT) !expression true if expression is false and
vice versa
EXAMPLE:

&& Operator:
 (3 > 5) && (4 < 5) returns false because expression (3 > 5) is false
 (3 < 5) && (4 < 5) returns true because they are both true
|| Operator:
 (3 == 5) || (4 > 5) returns false because they are both false
 (3==5) || (4 < 5) returns true because (4 < 5) is true
 (3 != 5) || (4 < 5) returns true because they are both true
! Operator:
 !(5 < 3) returns true because (5 < 3) is false
 !(5 > 3) returns false because (5 > 3) is true
Comma Operators
Coma Operators are used to put the related expressions together.
EXAMPLE:

References:
https://programmingwithbabu.wordpress.com/2017/08/22/operators-and-
expressions-part-iv-increment-and-decrement-operator/
https://press.rebus.community/programmingfundamentals/chapter/increment-and-
decrement-operators/
https://www.youtube.com/watch?v=Lpo1QYsuAmM
https://www.programiz.com/java-programming/operators

You might also like