Sie sind auf Seite 1von 8

Unary

Operand == data to be operated on


a+b

A= a+1 = +a; prefix

Operators
are special characters to manipulate primitive data types

Unary: Takes one argument.


These operators appear before its argument or after its argument.
Prefix
Postfix
Binary: Takes two arguments.
These operators appear between its arguments.
C = a+b
Ternary: Takes three arguments.
These operators appear between its arguments.
Different types of Operators

Assignment Operators = a + + a = a+1


A=1
A= a+1
A++
1 = 1+1
A+2
+a
A=a+1;
1 st assign
Value of a is taken
Adds to value of a
Then assigns

++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

Bit wise Operator >> > <

Compound Assignment Operators += -= *= /= %=

Assignment Operator

Assignment Operator is denoted by the symbol “=”


It assigns the value on the right to the variable on the left.
Assignment operator is <variable> = <expression>

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

Multiplication ‘*’ This multiplies two numbers

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

Increment ‘++’ This increases the value by 1

Decrement ‘- -‘ This decreases the value by 1

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

Equal ‘==’ Checks if the value of both operands are equal

Not Equal ‘!=’ Checks if the value of two operands are not equal

Logical operators

Return a true or false value based on the state of the Variables.

Each argument to a logical operator must be a boolean data type, and the result
is always a boolean data type.

The three commonly used logical operators

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

Ex: System.out.println("Check if both the boolean variables are true : " +


(Output_1 | | Output_2));

NOT Operator ‘!’ invert the state of the condition

Ex: System.out.println("Change the state of the Output_1 to false : " + (!Output_1));

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.

The operator is written as:

variable = (expression) ? value if true : value if false

ex:

int Thirty ;

int Twenty = 20;


int Ten = 10;

bValue = (Thirty = = Twenty + Ten) ? true: false;

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 );

b = (a = = 10) ? 100 : 200;


System.out.println( "Value of b is : " + b );

Bitwise Operators

Operator Description Example

~ Unary bitwise complement ~a

& Bitwise AND a&b

| Bitwise inclusive OR a|b


^ Bitwise exclusive OR a^b

<< Signed left shift a << b

>> Signed right sift a >> b

>>> Unsigned right shift a >>> b

Logical Operators

Operator Description Example

&& Logical AND Operator a && b

|| Logical OR Operator a || b

! Logical NOT Operator

Das könnte Ihnen auch gefallen