हिंदी

Illustrate '?' operator.

Advertisements

प्रश्न

Illustrate '?' operator.

कोड लेखन
लघु उत्तरीय
Advertisements

उत्तर

The Conditional Operator (?:) in Java is a ternary operator that evaluates a condition and selects one of two expressions depending on whether the condition is true or false. It is a shorter alternative to an if-else statement.

variable = (condition) ? expression1 : expression2;

Example:

class ConditionalOperator
{
    public static void main(String[] args)
    {
        int a = 10, b = 20;
        int max = (a > b) ? a : b;
        System.out.println("Greater Number: " + max);
    }
}

Output:

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

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×