MCQ Practice Single Best Answer Topic: Relational Operators

Q What is the value of the expression p > q if p is 10 and q is 15 in Java?

Question ID
#20134
Subchapter
Relational Operators
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A true
  • B false
  • C 10
  • D 15
Correct Answer: B

Explanation

The greater-than operator (>) in Java is used to check if the left operand is greater than the right operand. In this case, 10 > 15 is false because 10 is not greater than 15.

If p is 10 and q is 15, the expression p > q in Java evaluates to false. This is because 10 is not greater than 15.

Here's a simple Java program to illustrate this:


public class GreaterThanOperatorExample {
    public static void main(String[] args) {
        // Example values
        int p = 10;
        int q = 15;

        // Check if p is greater than q
        if (p > q) {
            System.out.println("p is greater than q.");
        } else {
            System.out.println("p is not greater than q.");
        }
    }
}

When you run this program, it will print "p is not greater than q."

Share This Question

Share this MCQ with your friends or study group.