Operators in Java are special symbols or keywords that help perform various operations, such as arithmetic, logical, and relational operations on variables and values.
Types of Operators
Some common types of operators are:
Arithmetic Operators: Perform basic mathematical operations like addition, subtraction, multiplication, division, and modulus.
Relational Operators: Compare two values and return true or false based on the comparison.
Logical Operators: Used to perform logical AND, OR, and NOT operations.
Assignment Operators: Assign values to variables.
Unary Operators: Operate on a single operand, such as incrementing or negating a value.
Arithmetic Operators
- Arithmetic operators are used to perform mathematical operations. These include:
Addition (+): Adds two values.
Subtraction (-): Subtracts one value from another.
Multiplication (*): Multiplies two values.
Division (/): Divides one value by another.
Modulus (%): Returns the remainder after division.