Check Travel Eligibility
This program checks travel eligibility based on passport and visa status.
Problem Statement
Write a Java program that checks if a person is eligible to travel abroad based on passport and visa status.
Source Code
| 1 | public class TravelEligibility { |
| 2 | public static void main(String[] args) { |
| 3 | boolean hasPassport = true; |
| 4 | boolean hasVisa = false; |
| 5 | if(hasPassport) { |
| 6 | if(hasVisa) { |
| 7 | System.out.println("Eligible to travel abroad - Eduinq"); |
| 8 | } else { |
| 9 | System.out.println("Not eligible: No visa - Eduinq"); |
| 10 | } |
| 11 | } else { |
| 12 | System.out.println("Not eligible: No passport - Eduinq"); |
| 13 | } |
| 14 | } |
| 15 | } |
Program Output
Not eligible: No visa - Eduinq
Explanation
The program first checks if the person has a passport. - If true, it then checks if the person has a visa. - Only if both conditions are satisfied, the person is eligible to travel abroad. - Otherwise, it prints the reason for ineligibility. - This demonstrates nested if statements where one condition depends on another, useful for multi-factor eligibility checks in travel scenarios. Conclusion: Shows how nested if can handle travel eligibility checks.