0
0
Javaprogramming~15 mins

Relational operators in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
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
1
Create age variables
Create two integer variables called ageAlice and ageBob with values 25 and 30 respectively.
Java
Need a hint?

Use int to declare whole number variables and assign the exact values.

2
Create relational boolean variables
Create boolean variables isAliceOlder, isBobOlder, and areSameAge that store the results of ageAlice > ageBob, ageBob > ageAlice, and ageAlice == ageBob respectively.
Java
Need a hint?

Use relational operators > and == to compare the ages and store the results in boolean variables.

3
Print the comparison results
Use System.out.println to print the values of isAliceOlder, isBobOlder, and areSameAge each on a new line.
Java
Need a hint?

Use System.out.println to show each boolean result on its own line.

4
Run and check output
Run the program and confirm the output shows false, true, and false each on a new line.
Java
Need a hint?

The output should be three lines: false, true, and false.