Advertisements
Advertisements
Question
Users must be above 10 years to open a self-operated bank account. Write this logic using a ternary operator and store the result (the eligibility message) in a String variable named idStatus and print it.
Long Answer
Advertisements
Solution
String idStatus = (age > 10) ? "Eligible" : "Not eligible";
System.out.println(idStatus);
- The expression
(age > 10)checks if the user's age is greater than 10. - The
?operator acts as theif. If the condition is true, "Eligible" is assigned. The:acts as theelse. If false, "Not eligible" is assigned. - The resulting message is stored in the String variable
idStatusas specifically requested in the question.
shaalaa.com
Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
