Next


Java Online Compiler

Java Unary Operators

Unary Operator:

If any operation perform on single operand (Variable) is known as uanry operrator.
These opeators are classified into following types.
  1. Unary Minus operator
  2. Incremnent operator
  3. Decrement operator
Unary Minus
Unary minus means sign value or minus value
example:
int x=10 then -x=-10;

class Main
{
 public static void main(String args[])
 {
  int x=10;
  System.out.println("the sign value is"+(-x));
 }
}

Java Incremnet Operators

Increment Operator:


Increment Operator is used to increment the one value to the current value. These are classified into following types.
  1. PreIncrement operator
  2. PostIncrement operator
PreIncrement Operator(++x)
PreIncrement oprator is used to increment the value first assign the value later. example:
int x=10 then ++x=11;

class Main
{
 public static void main(String args[])
 {
 int x=10;

  System.out.println("PreIncrement Is"+(++x));
 }
}

PostIncrement Operator(x++)
In the post incrementation assign the value first increment the value later. example:
int x=10 then x++=10;

class Main
{
 public static void main(String args[])
 {
 int x=10;

  System.out.println("PostIncrement Is"+(x++));
 }
}

Java Decrement Operators

Decrement Operator:


decrement Operator is used to decrement the one value to the current value. These are classified into following types.
  1. PreDecrement operator
  2. PostDecrement operator
PreDecrement Operator(- -x)
In the pre decrementation decrement the value first assign the value later.
example:
int x=10 then --x=9;

class Main
{
 public static void main(String args[])
 {
 int x=10;

  System.out.println("PreDecrement Is"+(--x));
 }
}


PostDecrement Operator(x- -)
In the post decrementation decrement the value first assign the value later.
int x=10 then x--=10;

class Main
{
 public static void main(String args[])
 {
 int x=10;

  System.out.println("Predecrement Is"+(x--));
 }
}