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
Post a Comment