banti babu
banti babu
Читать 1 минуту

What are Operators in Java | Types of Java Operators

Operators in Java are special symbols or keywords that are used to perform various operations on variables and values. There are several types of operators in Java, including arithmetic operators, relational operators, logical operators, bitwise operators, and assignment operators. In this blog post, we will discuss each of these operator types in more detail.

  1. Arithmetic Operators

Arithmetic operators are used to perform basic mathematical operations, such as addition, subtraction, multiplication, division, and modulus. The following table shows the arithmetic operators in Java:

int a = 10;

int b = 3;

int sum = a + b; // 13

int diff = a - b; // 7

int prod = a * b; // 30

int quotient = a / b; // 3

int remainder = a % b; // 1

2. Relational Operators

Relational operators are used to compare two values and return a boolean result. The following table shows the relational operators in Java:

int a = 10;

int b = 3;

boolean isEqual = a == b; // false

boolean isNotEqual = a != b; // true

boolean isGreater = a > b; // true

boolean isLess = a < b; // false

boolean isGreaterOrEqual = a >= b; // true

boolean isLessOrEqual = a <= b; // false

3. Logical Operators

Logical operators are used to perform logical operations on boolean values. The following table shows the logical operators in Java:

boolean a = true;

boolean b = false;

boolean and = a && b; // false

boolean or = a || b; // true

boolean notA = !a; // false

boolean notB = !b; // true

3 просмотра
Добавить
Еще
banti babu
Подписаться