English

Explain the following with an example segment: Unary Operator

Advertisements

Question

Explain the following with an example segment:

Unary Operator

Code Writing
Explain
Advertisements

Solution

A Unary Operator in Java is an operator that performs an operation on a single operand. It is used to increase, decrease, negate or change the value of an operand.

Common unary operators include increment (++), decrement (--), unary plus (+), unary minus (-) and logical NOT (!).

Example Code Segment:

int a = 10;
System.out.println(++a);
System.out.println(--a);

Output:

11
10
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 131]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 29. (iv) | Page 131
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×