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

Java Operators

Java Program
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Java Operators

Java Program
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 Arithmetic Operators
Arithmetic operators are used to perform arithmetic
operations on variables and data.
+ operator is
used to add two
variables
Using the + operator is the
most common way to concatenate
two strings in Java. You can provide
either a variable, a number, or a
String literal (which is always
surrounded by double quotes). Be
sure to add a space so that when
the combined string is printed, its
words are separated properly
EXAMPLE OF ARITHMETIC
OPERATIONS
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 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.

You might also like