OCA Java SE 8 Mock Exam Review - OCA Mock Question 40








Question

Select the options that, when inserted at // INSERT CODE HERE, will make the following code output a value of 11:

public class Main { 
    public static void main(String[] args) { 
        int ctr = 30; 
        // INSERT CODE HERE 
        System.out.println(ctr % 20); 
    } 
} 
  1. ctr += 1;
  2. ctr =+ 1;
  3. ++ctr;
  4. ctr = 1;




Answer



A, C

Note

To output a value of 11, the value of the variable ctr should be 31.

B is incorrect. Java does not define a =+ operator.

The correct operator is +=.

D is incorrect because it's assigning a value of 1 to the variable result, the result would be 1.