This Java program checks whether a person is eligible to vote based on their age. The program prompts the user to enter their age and uses a ternary operator to check whether the age is greater than or equal to 18. If the age is greater than or equal to 18, the program prints "You are Eligible for Voting". Otherwise, the program prints "You are Not Eligible for Voting". Here's how the program works:
Overall, this program is a simple example of using ternary operator and switch statement in Java to check eligibility for voting based on age.
import java.util.Scanner; public class Vote_Eligible { public static void main(String[] args) { Scanner input = new Scanner(System.in); int age = 0; System.out.printf("Enter the Age : "); age = input.nextInt(); int res = age >= 18?1:0; switch (res) { case 0: System.out.printf("You are Not Eligible for Voting..."); break; case 1: System.out.printf("You are Eligible for Voting..."); break; } } }
Enter the Age : 23 You are Eligible for Voting...
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions