Loading...
Loading...
Loading...
A person can vote if they are a citizen and at least 18 years old. Read a person's age and a letter that says whether they are a citizen (Y or N) and print:
Eligible when they can vote;Not eligible: not a citizen when they are not a citizen (whatever their age);Not eligible: under 18 when they are a citizen but younger than 18.Y or N.Y or N (capital).Example 1
Input
19 Y
Output
Eligible
A citizen aged 19 can vote.
Example 2
Input
16 Y
Output
Not eligible: under 18
A citizen, but younger than 18.
Example 3
Input
30 N
Output
Not eligible: not a citizen
Not a citizen, so age does not matter.
Try the problem first. Open one hint at a time.
Read the letter with sc.next().charAt(0) and compare it with 'Y' using ==.
Check citizenship first. Only inside the citizen branch does the age matter, so use a nested if.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor