Explain the following operator with an example program: Increment and Decrement Operator
Advertisements
प्रश्न
Explain the following operator with an example program:
Increment & Decrement Operator
कोड लेखन
स्पष्ट कीजिए
Advertisements
उत्तर
The Increment Operator (++) in Java is a unary operator used to increase the value of a variable by 1, whereas the Decrement Operator (--) is a unary operator used to decrease the value of a variable by 1.
Both operators can be used in prefix (++a, --a) and postfix (a++, a--) forms.
Example:
class IncrementDecrement
{
public static void main(String[] args)
{
int a = 10, b = 20;
a++;
b--;
System.out.println("Increment: " + a);
System.out.println("Decrement: " + b);
}
}
Output:
Increment: 11
Decrement: 19
Decrement: 19
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
