November 3 2014

Unary Operator Java

Unary Operator Java (-)

Unary Operator is used to negate  a value. Negation is converting negative number to positive number and positive number to negative number.


-variable or – value


In the following example value of a is 10 and -a is assigned to b. Value of b becomes -10. Value of c is -20 and -c is assigned to d so value of d become +20;

public class UnaryOperatorJava {

public static void main(String[] args) {

int a=10;
int b=-a;

System.out.println("Value of b: "+b);

int c=-20;
int d=-c;

System.out.println("Value of d: "+d);




Value of b: -10
Value of d: 20

Copyright © 2014. All rights reserved.

Posted November 3, 2014 by answersz in category Bluej Java Programs for ICSE Class 10 and 9 Practice, Core Java

Leave a Comment

Your email address will not be published. Required fields are marked *