Create a program to demonstrate the use of Unary Operators in java

 Create a program to demonstrate the use of Unary Operators in java

public class UnaryOperater
{
   public static void main(String args[]){
    int a=20,result;
    result=+a;
    System.out.println(result); //Result is still 20
    result=-a;
    System.out.println(result); //Result is now -20
    result=++a;
    System.out.println(result); //Result is now 21
    result=--a;
    System.out.println(result); //Result is now 20
    result=a++;
    System.out.println(result); //Result is now 20
    result=a--;
    System.out.println(result); //Result is now 21
    }
}
Output
20 -20 21 20 20 21

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Make a GST Calculator using HTML and JavaScript

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java