Programs on Operators
1. Program to illustrate arithmetic operators.
class ArithmaticOperator
{
public static void main(String arg[])
{
int x=40;
int y=20;
System.out.println("Addition Of Two Number Is: "+(x+y));
System.out.println("Substraction Of Two Number Is: "+(x-y));
System.out.println("Multiplication Of Two Number Is: "+(x*y));
System.out.println("Division Of Two Number Is: " +(x/y));
System.out.println("Modulus Of Two Number Is: " +(x%y));
}
}
2. Program to illustrate Increment operators.
class Increment
{
public static void main(String args[])
{
int a=20;
int b=10;
//---------*Pre Increment Operator*-----------
System.out.println("*Pre Icrement Operator*");
System.out.println("Enter the value "+(++a));
System.out.println("Enter the value "+(++a + b));
System.out.println("Enter the value "+(++a - b));
System.out.println("Enter the value "+(++a * b));
System.out.println("Enter the value "+(++a / b));
System.out.println("Enter the value "+(++a % b));
//---------*Post Increment Operator*-----------
System.out.println("*Post Increment Operator*");
System.out.println("Enter the value "+(a++));
System.out.println("Enter the value "+(a++ + b));
System.out.println("Enter the value "+(a++ - b));
System.out.println("Enter the value "+(a++ * b));
System.out.println("Enter the value "+(a++ / b));
System.out.println("Enter the value "+(a++ % b));
}
}
3. Program to illustrate decrement operators.
class Decrement
{
public static void main(String args[])
{
int a=20;
int b=10;
//---------*Pre Decrement Operator*-----------
System.out.println("*Pre Decrement Operator*");
System.out.println("Enter the value "+(--a));
System.out.println("Enter the value "+(--a + b));
System.out.println("Enter the value "+(--a - b));
System.out.println("Enter the value "+(--a * b));
System.out.println("Enter the value "+(--a / b));
System.out.println("Enter the value "+(--a % b));
//---------*Post Decrement Operator*-----------
System.out.println("*Post Decrement Operator*");
System.out.println("Enter the value "+(a--));
System.out.println("Enter the value "+(a-- + b));
System.out.println("Enter the value "+(a-- - b));
System.out.println("Enter the value "+(a-- * b));
System.out.println("Enter the value "+(a-- / b));
System.out.println("Enter the value "+(a-- % b));
}
}
4. Program to illustrate relational operators.
class Relational
{
public static void main(String [] args)
{
int a=10,b=20;
System.out.println(" "+(a<b));
System.out.println(" "+(a<=b));
System.out.println(" "+(a>b));
System.out.println(" "+(a>=b));
System.out.println(" "+(a!=b));
System.out.println(" "+(a==b));
}
}
5. Program to illustrate bitwise operators.
class Bitwise
{
public static void main(String arys[])
{
int a=5,b=6;
System.out.println("&:- "+(a&b));
System.out.println("|:- "+(a|b));
System.out.println("^:- "+(a^b));
System.out.println("~:- "+(~a));
System.out.println(">>:- "+(a>>b));
System.out.println("<<:- "+(a<<b));
}
}
6. Program to illustrate ternary operator.
class Ternary
{
public static void main(String args[])
{
int a=20,b=40,max;
max=(a>b)? a:b;
System.out.print(max);
}
}