0% found this document useful (0 votes)
10 views

Java Operators (Update)

This document discusses different types of operators in Java including arithmetic, assignment, relational, logical, and unary operators. It provides examples of how the + operator is used to add two variables, the = operator to assign values to variables, the > operator to check if one value is greater than another, and the ++ operator to increment a variable by 1. It also explains how the ++ and -- operators can be used as both prefix and postfix to increment or decrement a variable either before or after returning its value.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Java Operators (Update)

This document discusses different types of operators in Java including arithmetic, assignment, relational, logical, and unary operators. It provides examples of how the + operator is used to add two variables, the = operator to assign values to variables, the > operator to check if one value is greater than another, and the ++ operator to increment a variable by 1. It also explains how the ++ and -- operators can be used as both prefix and postfix to increment or decrement a variable either before or after returning its value.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Java Operators

1.Arithmetic Operators
2.Assignment Operators
3.Relational Operators
4.Logical Operators
5.Unary Operators
Java Arithmetic Operators
Arithmetic operators are used to perform arithmetic
operations on variables and data.

+ operator is
used to add
two variables
Java Assignment Operators
Assignment operators are used in Java to
assign values to variables

= is the assignment operator. It


assigns the value on its right to the
variable on its left. That is, 5 is
assigned to the variable age
Java Assignment Operators
Java Assignment Operators
Example
Java Relational Operators
Relational operators are used to check the
relationship between two operands

> operator is the relational


operator. It checks if a is less
than b or not. It returns either
true or false
Java Relational Operators
Relational operators are used in decision making
and loops.
Java Relational Operators
Java Logical Operators
Logical operators are used to check whether an expression is true or
false. They are used in decision making.
Java Logical Operators
Java Logical Operators
Java Unary Operators
Unary operators are used with only one operand. For
example, ++ is a unary operator that increases the value of a
variable by 1.

Example : ++5 will


return to 6
Increment and Decrement
Operators
Java also provides increment and decrement operators: ++ and -- respectively. ++
increases the value of the operand by 1, while -- decrease it by 1.
Increment ++ and Decrement -- Operator as
Prefix and Postfix
In programming (Java, C, C++, JavaScript etc.), the increment operator ++
increases the value of a variable by 1. Similarly, the decrement operator --
decreases the value of a variable by 1.

++ and -- operator as prefix and postfix


If you use the ++ operator as a prefix like: ++var, the
value of var is incremented by 1; then it returns the
value.
If you use the ++ operator as a postfix like: var++, the
original value of var is returned first; then var is
incremented by 1.
The -- operator works in a similar way to the ++
operator except -- decreases the value by 1.
Increment ++ and Decrement -- Operator
as Prefix and Postfix

You might also like