Hello friends, welcome back to the 100 Days of Java series.
So far, we have taught Java how to do math, take inputs, and calculate results. But here is the real question:
How do we teach a computer to make decisions?
For example:
- If you are under 13, you should not watch horror movies.
- If you are 18 or older, you can watch anything.
This is where if else conditions come in.
What is If Else
Think of it like this:
If it is raining, take an umbrella.
Else, wear sunglasses.
It is basically telling the computer:
“Check this condition, do this if it is true, otherwise do that.”
The structure in Java looks like this:
if (condition) {
// code runs if condition is true
} else {
// code runs if condition is false
}
Age-based Movie Recommendation Example
Let’s build a small program that recommends movies based on the user’s age.
import java.util.Scanner;
public class MovieRecommendation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = sc.nextInt();
if (age < 13) {
System.out.println("We recommend: Animated movies like Frozen or Toy Story!");
} else if (age < 18) {
System.out.println("We recommend: Teen movies like Spider-Man or Harry Potter!");
} else if (age < 60) {
System.out.println("We recommend: Action or Drama like Avengers or Inception!");
} else {
System.out.println("We recommend: Classic movies like The Godfather or Sound of Music!");
}
}
}
Example Run
Enter your age: 10
We recommend: Animated movies like Frozen or Toy Story!
Enter your age: 25
We recommend: Action or Drama like Avengers or Inception!
Iron Man Reference
Imagine Tony Stark’s helmet.
If the enemy is a robot, use the EMP blast.
Else if it is Thanos, call Hulk.
Else, just fly away.
That is exactly how if else works. Jarvis is constantly checking conditions before taking action.
Wrap Up
Today we learned:
- How to use if else conditions in Java
- How conditional logic helps programs make decisions
- Built a movie recommendation app based on age
Tomorrow, we will go deeper into nested if else and switch statements to handle multiple layers of choices.
References
You can also check out:
- Learn Java Basics (Day 1) – Install JDK and Run Your First Program
- Learn Java Variables and Data Types (Day 2): Java for Beginners
- Day 3: Java Variables and Data Types Explained with Real-Life Examples
- Day 4 Java Tutorial: Scanner Input + Build a Basic Calculator
- Day 5 – Operators and Expressions in Java with Grocery Price Calculator
- Beginner’s Guide to Web Development
About Us
- Akhil Boddu’s YouTube Channel – Follow my vlogs for personal experiences and tips.
- Code With Me YouTube Channel – Explore tech tutorials and coding advice.
- WeblogTrips LinkedIn – Connect with me on LinkedIn for more insights and discussions.
If the information you are looking for is not available here, please contact us. Additionally, follow us on our social media platforms for updates and more information.







