Time: 15 minutes
Purpose: This activity helps you get familiar with using relational operators as well as the outputs you get from them.
Introduction: Youโre had experience using other operators, now is a chance to get a good feel for how relational operators work and what they output
Task: Declare num1, num2, num3 as integers.
Set num1 and num2 to 6.
Set num3 to 12.
- Print if true/false num1 is equivalent to num2
- Print if true/false num3 is less than num2.
- Print if true/false num1 is greater than num2.
- Print if true/false num1 is greater than or equal to num2.
int num1 = 6, num2 = 6, num3 = 12;
booleanResult = (num1 == num2);
System.out.println("Is num1 (" + num1 + ") == num2 (" + num2 + ") ? Result: " + booleanResult);
booleanResult = (num3 < num2);
System.out.println("Is num3 (" + num3 + ") < num2 (" + num2 + ") ? Result: " + booleanResult);
booleanResult = (num1 > num2);
System.out.println("Is num1 (" + num1 + ") > num2 (" + num2 + ") ? Result: " + booleanResult);
booleanResult = (num1 >= num2);
System.out.println("Is num1 (" + num1 + ") >= num2 (" + num2 + ") ? Result: " + booleanResult);
Good work. That all looks to be in order.