Unary Operator plus, minus and inversion
Understanding unary operator plus, minus and inversion.
- Learning to use unary positive, negative and inversion operator.
Integer variable a is initialised with +5. This is unary plus operator. If this is not given the + value automatically assumed.
Negated value of a is stored in b. Which means b will contain -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.
Value as computed before are printed here
- The unary + operator can serve a specific purpose of converting a character to integer. For e.g.
char c=65; System.out.println(c); System.out.println(+c); will result in A and 65 respectively
- The unary operator documentation can be studied from
Suggested Filename(s): UnaryNegNot.java
sunmitra| Created: 3-Mar-2018 | Updated: 3-Mar-2018|