मराठी

Explain the following operator with an example program: Unary Operator

Advertisements

प्रश्न

Explain the following operator with an example program:

Unary Operator

कोड लेखन
स्पष्ट करा
Advertisements

उत्तर

A Unary Operator in Java is an operator that performs an operation on a single operand. Unary operators include unary plus (+), unary minus (-), increment (++), decrement (--) and logical NOT (!).

Example:

class UnaryOperator
{
    public static void main(String[] args)
    {
        int a = 10;
        boolean b = true;
        System.out.println("Unary Plus: " + (+a));
        System.out.println("Unary Minus: " + (-a));
        System.out.println("Increment: " + (++a));
        System.out.println("Decrement: " + (--a));
        System.out.println("Logical NOT: " + (!b));
    }
}

Output:

Unary Plus:
10 Unary Minus: -10
Increment: 11
Decrement: 10
Logical NOT: false
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Variables and Expressions - EXERCISE [पृष्ठ १३२]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
पाठ 6 Variables and Expressions
EXERCISE | Q 31. (f) | पृष्ठ १३२
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×