What is an Increment Operator in Java? Explain with an example.
Advertisements
प्रश्न
What is an Increment Operator in Java? Explain with an example.
स्पष्ट करा
Advertisements
उत्तर
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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Variables and Expressions - EXERCISE [पृष्ठ १३१]
