0:07 [Music]
0:10 Welcome back to code chef. Have you ever
0:12 compared two things? Like checking if
0:14 your test score is greater than your
0:17 friends or whether two prices are equal.
0:20 In Java, we use relational operators to
0:21 let the computer make these comparisons
0:24 for us. Think of relational operators
0:27 like traffic lights for decisions. Green
0:30 means yes, the condition is true. Red
0:34 means no, the condition is false. Just
0:36 like traffic lights guide cars,
0:38 relational operators guide Java in
0:40 deciding the flow of a program.
0:42 Relational operators compare two values
0:45 and return either true or false. The
0:48 main operators are double equals equal
0:52 to, exclamation equals not equal to,
0:56 greater than, less than, greater than or
0:59 equal to, and less than or equal to.
1:02 Here's a simple example. We declare two
1:06 variables. A= 10 and B= 20. Now, let's
1:10 compare them. A= B is false because 10
1:13 is not equal to 2020. A less than B is
1:16 true since 10 is less than 20 and a
1:19 greater than or equal to B is false
1:21 because 10 is not greater than or equal
1:24 to 20. Each comparison gives us a true
1:27 or false result. A few quick tips.
1:29 Relational operators always return true
1:32 or false. They're most often used in
1:34 conditions like if statements and loops.
1:36 And remember, don't mix them with
1:38 strings for now. We'll cover string
1:42 comparisons later. Now it's your turn.
1:44 Try the code chef problem. Is it a
1:46 score? You'll practice using relational
1:48 operators to compare values just like we
1:52 did here. Today you learned relational
1:54 operators compare two values, return
1:57 true or false, and form the backbone of
2:00 decision-m in Java programs. Code,
2:02 debug, repeat. Build mastery with CodeChef.
2:03 CodeChef. [Music]