Operators (Arithmetic)

Author: Ravi Poswal

An operator is a symbol or keyword that instructs a computer to manipulate values (operands) in a particular way using logic, mathematics, or data. The symbol for "operator" in Java is broken down into the following categories:

  1. Arithmetic operator

  2. Relational operator

  3. Bitwise operator/ Shift operator

  4. Ternary operator

  5. Logical operator

  6. Assignment operator

  7. Increment/Decrement operator

The above operators are classified into two main categories: unary operators and binary operators.

A binary operator requires two operands to perform a calculation or operation. For example, operators like +, -, *, and / work with two values, such as a + b.

On the other hand, a unary operator works with only one operand. It performs an operation on a single value. Examples of unary operators include the increment (++) and decrement (--) operators, which increase or decrease the value of a variable by one.

1. ARITHMETIC OPERATOR

Arithmetic operators are used to perform mathematical operations: addition (+), subtraction (-), multiplication (*), division (/), and modulo (%) with operands.

Example: (A*B), (A/B), (A%B), (A+B), (A-B)

Code Example

import java.util.*;
class A
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
int z=x+y;
int r=x-y;
int w=x*y;
int p=x/y;
System.out.println(" hello "+z);
System.out.println(" hello "+r);
System.out.println(" hello "+w);
System.out.println(" hello "+p);
} }