हिंदी

Explain the following operator with an example program: Conditional Operator

Advertisements

प्रश्न

Explain the following operator with an example program:

Conditional 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

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Variables and Expressions - EXERCISE [पृष्ठ १३२]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 6 Variables and Expressions
EXERCISE | Q 31. (e) | पृष्ठ १३२
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×