Check Driving Eligibility

This program checks driving eligibility based on age and license status.

Problem Statement

Write a Java program that checks if a person is eligible to drive based on age and license status.

Source Code

1 public class DrivingEligibility {
2 public static void main(String[] args) {
3 int age = 20;
4 boolean hasLicense = true;
5 if(age >= 18) {
6 if(hasLicense) {
7 System.out.println("Eligible to drive - Eduinq");
8 } else {
9 System.out.println("Not eligible: No license - Eduinq");
10 }
11 } else {
12 System.out.println("Not eligible: Underage - Eduinq");
13 }
14 }
15 }

Program Output

Eligible to drive - Eduinq

Explanation

The program first checks if age is 18 or above. - If true, it then checks if the person has a license. - Only if both conditions are satisfied, the person is eligible to drive. - Otherwise, it prints the reason for ineligibility. - This demonstrates nested if statements where one condition depends on another, useful for multi-factor eligibility checks. Conclusion: Shows how nested if can handle driving eligibility checks.

Quick Links to Explore