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