Java OCA OCP Practice Question 2377

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 = 50; 
        // INSERT CODE HERE 
        System.out.println(ctr % 20); 
    } 
} 
  • a ctr += 1;
  • b ctr =+ 1;
  • c ++ctr;
  • d ctr = 1;


a, c

Note

To output a value of 11, the value of the variable ctr should be 51 because 51%20 is 11.

Operator % outputs the remainder from a division operation.

The current value of the variable ctr is 50.

It can be incremented by 1 using the correct assignment or increment operator.

Option (b) is incorrect.

Java does not define a =+ operator.

The correct operator is +=.

Option (d) is incorrect because it's assigning a value of 1 to the variable result, not incrementing it by 1.




PreviousNext

Related