Java if Else Practice Questions
Java if Else Practice Questions
1. Eligibility to Vote
Write a Java program that checks if a person is eligible to vote. The user inputs their
age.
Logic:
import java.util.Scanner;
Logic:
import java.util.Scanner;
if (num % 2 == 0) {
System.out.println(num + " is even.");
} else {
System.out.println(num + " is odd.");
}
}
}
3. Temperature Check
Write a program to give clothing advice based on the temperature:
- >30°C -> "It's hot, wear light clothes"
- 15-30°C -> "Nice weather, dress comfortably"
- <15°C -> "It's cold, wear a jacket"
Java If-Else Practice Questions (Real-Life Examples)
Logic:
import java.util.Scanner;
Logic:
import java.util.Scanner;
5. ATM Withdrawal
Simulate an ATM machine that checks if the user has enough balance to withdraw money.
Logic:
import java.util.Scanner;