Unary Operator plus, minus and inversion – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Code Learning #JAVA#3692 siteicon   siteicon   siteicon  

Unary Operator plus, minus and inversion

Understanding unary operator plus, minus and inversion.

Learning Objectives

  • Learning to use unary positive, negative and inversion operator.

Source Code

TC++ #3692

Source Code

Run Output

-5
true

Code Understanding

int a=+5;
Integer variable a is initialised with +5. This is unary plus operator. If this is not given the + value automatically assumed.

int b=-a;
Negated value of a is stored in b. Which means b will contain -5

boolean c=!(a>5);
Here the result of a>5 which would be boolean false will be inverted by the use of ! operator so c would contain a true value.

System.out.println(b);
System.out.println(c);
Value as computed before are printed here

Notes


Suggested Filename(s): UnaryNegNot.java



Share

sunmitra| Created: 3-Mar-2018 | Updated: 3-Mar-2018|






Back