OCA Java SE 8 Mock Exam 2 - OCA Mock Question 5








Question

Which of the following expressions will evaluate to 7?

  1. 2 + 4 * 3- 7
  2. (2 + 4) * (3 - 7)
  3. 2 + (4 * 3) - 7
  4. ((2 + 4) * 3) - 7)




Answer



A and C

Note

Option b evaluates to -24. Option d evaluates to 11.

public class Main {
  public static void main(String[] args) {
    System.out.println(2 + 4 * 3- 7 );
    System.out.println((2 + 4) * (3 - 7) );
    System.out.println(2 + (4 * 3) - 7 );
    System.out.println(((2 + 4) * 3) - 7 );

  }
}