English

What is an Increment Operator in Java? Explain with an example.

Advertisements

Question

What is an Increment Operator in Java? Explain with an example.

Explain
Advertisements

Solution

The Increment Operator (++) in Java is a unary operator used to increase the value of a variable by one. It can be used in two forms: Pre-increment (++a), which increases the value before it is used, and Post-increment (a++), which increases the value after it is used.

Example:

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

Output:

11

In the above example, the variable a is initialised with the value 10. The increment operator (++) increases its value by one. Therefore, after executing a++, the value of a becomes 11.

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

Englishहिंदीमराठी


      Forgot password?
Use app×