English

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 - Computer Applications

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);
  1. The expression (age > 10) checks if the user's age is greater than 10.
  2. The ? operator acts as the if. If the condition is true, "Eligible" is assigned. The : acts as the else. If false, "Not eligible" is assigned.
  3. The resulting message is stored in the String variable idStatus as specifically requested in the question.
shaalaa.com
  Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×