To check whether the person is eligible the vote or not, the Person should complete the age of 18. This means A person age 18 or more is eligible/valid to give a vote.
Now using Java we have to write a program that will tell whether the given age is eligible to vote or not.
For Example:
Suppose a Age given is 15
Then output should be “Person is not eligible for Vote”.
And if the Age input is 33
Then output should be “Person is eligible for Vote”.
Java program to check eligibility for voting
import java.util.*;
public class Main
{
public static void main (String[]args)
{
// Declaring variables
int age;
// Taking age as input
Scanner scan = new Scanner(System.in);
System.out.println("Please Enter Your Age: ");
age = scan.nextInt();
// Condition for vote
if(age>=18)
{
System.out.println("You are eligible for voting.");
}
else
{
System.out.println("You are not eligible for voting.");
}
}
}
Output 1:
Please Enter Your Age:
56
You are eligible for voting.
Output 2:
Please Enter Your Age:
12
You are not eligible for voting.