Person Eligibility (Age Check) in Java
Check if a person is eligible to vote based on age.
BeginnerModule 2: Conditional ProgramsExample 15 of 20
person-eligibility-age-check.java
1import java.util.Scanner;23public class Main {4 public static void main(String[] args) {5 Scanner sc = new Scanner(System.in);67 System.out.print("Enter age: ");8 int age = sc.nextInt();910 if (age >= 18) {11 System.out.println("Eligible to vote");12 } else {13 System.out.println("Not eligible to vote");14 }1516 sc.close();17 }18}
Output
Enter age: 20 Eligible to vote
What's going on
We compare age against the legal voting age threshold 18.