Java
Programming
S E M . IV-BC A
Operators
Java operators are special symbols .
Operators perform operations on variables or values .
These operators play a crucial role in performing
arithmetic, logical,
relational, and bitwise operations etc.
Java provides a rich set of operators to manipulate
variables .
Types of Operators –
1. Arithmetic Operators .
2. Relational Operators .
3. Bitwise Operators .
4. Logical Operators .
5. Assignment Operators .
6. Conditional Operators .
7. Unary Operators .
Arithmetic Operator – Program :
Import java.util.* ;
Class Arithmetic
o Arithmetic operators are
used in mathematical {
expressions . Public Static void main(String args[ ]);
{
o The list of arithmetic
operators as follows : int num1,num2,sum;
Scanner s=new Scanner(System.in);
1. Addition Name Symbo Example System.out.println(“Enter the first number“);
l
2. Subtraction Addition + a=10,b=20 a+b=30
num1= nextInt();
System.out.println(“Enter the second
3. Multiplication Subtraction - a=5,b=2 a-b=3 number=“);
Multiplication * a=2,b=3 a*b=6 num2= nextInt();
4. Division
Division / a=4,b=2 a/b=2 Sum=num1+num2;
5. modules System.out.println(“Addition=”+sum);
}
.
Relational Operator - o Program
o Relational Operators are used to check for import java.util.*;
relations . class RelationalOperators
{
public static void main(String[] args)
o The return value of a comparison is either {
true of false . Scanner scan = new Scanner(System.in);
int num1 =1;
o Relational operator is also known as int num2 = 2;
comparison operator . System.out.println("num1 > num2 is " + (num1 > num2));
System.out.println("num1 < num2 is " + (num1 < num2));
System.out.println("num1 >= num2 is " + (num1 >=
num2));
System.out.println("num1 <= num2 is " + (num1 <=
num2));
System.out.println("num1 == num2 is " + (num1 ==
num2));
System.out.println("num1 != num2 is " + (num1 != num2))
}
}
BITWISE OPERATOR –
o Bitwise operator works on bits and
performs bit by bit operation .
o The following list are the bitwise
operator .
1. Bitwise AND –(&)
2. Bitwise OR-(I)
3. Bitwise XOR – (^)
4. Bitwise Complement-(~)
5. Right shift operator – (>>)
6. Left shift operator – (<<)
o Program
Logical Oprator -
import java.util.*;
o Logical operators are used to class Logical
perform logical “AND”, “OR” and {
“NOT” operations . public static void main(String[]
o The following list are the logical args)
operator . {
1. Logical AND Oprerator –(&&) int a = 10, b = 20, c = 20;
Scanner s=new Scanner (System.in);
2. Logical OR Operator –(II)
System.out.println("Var1 = " +
3. Logical NOT Operator –(!) a);
System.out.println("Var2 = " +
b);
System.out.println("Var3 = " +
c);
if ((a < b) && (b == c))
{
System.out.println(“True
condition" );
}
Conditional Operator -
o Conditional operator is also known as
ternary operator.
o The operator is written as follows :
Variable X=(expression)? Value if true :
value if false
Add a Slide
Title - 4
Click icon to add picture
Add a Slide
Title - 5