Person Eligibility (Age Check)

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

BeginnerTopic: Module 2: Conditional Programs
Back

Java Person Eligibility (Age Check) Program

This program helps you to learn the fundamental structure and syntax of Java programming.

Try This Code
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

Understanding Person Eligibility (Age Check)

We compare age against the legal voting age threshold 18.

Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.

Table of Contents