arithmetic operator

Arithmetic, Assignment and Unary Operator in Java

arithmetic operatorIn this chapter you will learn:

  1. What is assignment operator and their symbol?
  2. What is arithmetic operator and their symbol?
  3. What is unary operator and their symbol?
  4. Programming example

What is assignment operator in Java?

Assignment(=) operator is most common operator in Java. It is used for assigning value to variable. For example
int num = 5;

What is arithmetic operator in java?

Arithmetic operator is an operator which provides addition, subtraction, multiplication, division and reminder. It performs mathematical operation on operands.

+It is called as Plus operator which adds integral value.num1 + num2
It is called Minus operator which subtracts integral value.num1 – num2
*It is called Multiply operator which multiply integral value.num1 * num2
/It is called Divide operator which divide integral value.num1 / num2
%It is called Reminder operator which tells reminder of two integral values.num1 % num2
Programming Example:



D:\JavaProgram>java ArithmeticOperators
Addition : 30
Subtraction : 10
Multiplication : 200
Division : 2
Reminder : 2

D:\JavaProgram> __

What is unary operator?

Unary operator is such kind of operator which requires only one operand to perform task. This type of operator is used for increasing or decreasing value, negating the expression or inverting the Boolean value.

+Unary Plus Operator: It indicates positive value. (However numbers are positive by default)35 or +35
Unary Minus Operator: It indicates negative value-35
++Increment Operator: It increment value by 1num1++
Decrement Operator: It decrements value by 1num1–
!Logical Complement Operator: (also known as Not Operator) – It inverts the Boolean expression. (true to false or false to true)if(!(true))

Programming Example



D:\JavaProgram>java UnaryOperator

D:\JavaProgram> __


In this chapter you have learned about assignment, arithmetic and unary operator in java. The next chapter you will learn about Relational Operator in Java.

Leave a Reply

Your email address will not be published. Required fields are marked *