MCQ Single Best Answer Easy

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

ID: #20134 Relational Operators 106 views
Question Info
#20134Q ID
EasyDifficulty
Relational OperatorsTopic

Choose the Best Option

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

  • A true
  • B false
  • C 10
  • D 15
Correct Answer: Option 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

Challenge a friend or share with your study group.