Single Choice Easy

QIf a is 15 and b is 7, what is the result of the expression a - b using the subtraction operator in Java?

ID: #20128 Arithmetic Operators in Java 115 views
Question Info
#20128Q ID
EasyDifficulty
Arithmetic Operators in JavaTopic

Choose the Best Option

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

  • A 8
  • B 22
  • C -8
  • D 7
Correct Answer

Explanation

The subtraction operator (-) in Java is used to subtract the right operand from the left operand. In this case, 15 - 7 equals 8.


public class SubtractionExample {
    public static void main(String[] args) {
        // Define the values of a and b
        int a = 15;
        int b = 7;

        // Use the subtraction operator to calculate a - b
        int result = a - b;

        // Display the result
        System.out.println("Result of a - b: " + result);
    }
}

When you run this program, it will output:


Result of a - b: 8

Share This Question

Challenge a friend or share with your study group.