Person Eligibility (Age Check)

Check if a person is eligible to vote based on age.

JavaBeginner
Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter age: ");
        int age = sc.nextInt();

        if (age >= 18) {
            System.out.println("Eligible to vote");
        } else {
            System.out.println("Not eligible to vote");
        }

        sc.close();
    }
}

Output

Enter age: 20
Eligible to vote

We compare age against the legal voting age threshold 18.