English

What is a Decrement Operator in Java? Explain with an example.

Advertisements

Question

What is a Decrement Operator in Java? Explain with an example.

Explain
Advertisements

Solution

The Decrement Operator (--) in Java is a unary operator used to decrease the value of a variable by one. It can be used in two forms: Pre-decrement (--a), which decreases the value before it is used, and Post-decrement (a--), which decreases the value after it is used.

Example:

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

Output:

9

In the above example, the variable a is initialised with the value 10. The decrement operator (--) decreases its value by one. Therefore, after executing a--, the value of a becomes 9.

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 17. (ii) | Page 131
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×