Beruflich Dokumente
Kultur Dokumente
Operators
are special characters to manipulate primitive data types
++a;
A=1assigns
Value of a is taken
adds
= 1+1
a=2
Arithmetic Operators - + * / % ++
a= --a
Relational Operators > < >= <= = = !=
Logical Operators && || & | !^
Conditional Operator ? if(a = =b)? a, b
Assignment Operator
Arithmetic operators
Perform the basic operations of mathematics.
They take two operands and return the result of the mathematical calculation.
Seven arithmetic operators available
Addition ‘+’ This add two numbers or concatenate two strings
Subtraction ‘-‘ This subtracts right side operand from the left side operand
Division ‘/’ This divides left side operand by the right side operand
Modulo ‘%’ This divides left side operand by the right side operand and
returns remainder
Relational Operators
are used to determine the comparison between two or more objects.
These operators always return the boolean value either true or false when used
in an expression.
Six different relational operators
Greater than ‘>’ Checks if the value of left operand is greater than value of
right operand
Less than ‘<‘ Checks if the value of left operand is less than the value of
right operand
Greater than or Equal to ‘>=’ Checks if the value of left operand is greater
than or equal to the value of right operand
Less than or Equal to ‘<=’ Checks if the value of left operand is less than or
equal to the value of right operand
Not Equal ‘!=’ Checks if the value of two operands are not equal
Logical operators
Each argument to a logical operator must be a boolean data type, and the result
is always a boolean data type.
And Operator ‘&&’ returns true if the output of both the operands are true
Ex:
boolean Output_1 = true;
boolean Output_2 = false;
System.out.println("Check if both the boolean variables are true : " +
(Output_1 && Output_2));
OR Operator ‘||’ returns true if the output of either operands are true
Conditional operator
The conditional operator is equivalent to if-else statement, known as the ternary operator.
This operator consists of three operands and is used to evaluate Boolean expressions.
The operator is to decide which value should be assigned to the variable.
ex:
int Thirty ;
result = true
EXAMPLE
int a = 10 , b ;
System.out.println("Conditional Operators");
b = (a = = 1) ? 100 : 200;
System.out.println( "\n Value of b is : " + b );
Bitwise Operators
Logical Operators
|| Logical OR Operator a || b