Single Choice Easy

QWhich relational operator is used to check if two values are equal in Java?

ID: #20132 Relational Operators 94 views
Question Info
#20132Q ID
EasyDifficulty
Relational OperatorsTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A ==
  • B !=
  • C >
  • D <=
Correct Answer

Explanation

The equality operator (==) in Java is used to check if two values are equal. It returns true if the values are equal and false otherwise.


public class EqualityOperatorExample {
    public static void main(String[] args) {
        // Example values
        int number1 = 5;
        int number2 = 7;

        // Check if the values are equal
        if (number1 == number2) {
            System.out.println("The values are equal.");
        } else {
            System.out.println("The values are not equal.");
        }
    }
}

In this example, number1 and number2 are compared using the equality operator (==). If the values are equal, it prints "The values are equal"; otherwise, it prints "The values are not equal."

No Previous Next Question

Share This Question

Challenge a friend or share with your study group.