Relational Operators in Java
📖 Scenario: You are creating a simple program to compare ages of two friends to see who is older or if they are the same age.
🎯 Goal: Build a Java program that uses relational operators to compare two age values and prints the comparison results.
📋 What You'll Learn
Create two integer variables named
ageAlice and ageBob with exact values 25 and 30 respectively.Create a boolean variable named
isAliceOlder that stores the result of comparing if Alice is older than Bob.Create a boolean variable named
isBobOlder that stores the result of comparing if Bob is older than Alice.Create a boolean variable named
areSameAge that stores the result of checking if Alice and Bob have the same age.Print the values of
isAliceOlder, isBobOlder, and areSameAge each on a new line.💡 Why This Matters
🌍 Real World
Comparing values is common in real life, like checking if someone is old enough to vote or drive.
💼 Career
Understanding relational operators is essential for decision-making in programming, used in conditions and loops.
Progress0 / 4 steps