What is the final value of a after the loops are executed in the following…

PYQ IBPS SO CRP SPL-XII (2022)

What is the final value of a after the loops are executed in the following program?

public class Main {
    public static void main(String[] args) {
        int a = 0;
        for (int i = 0; i < 5; i++) {
            a++;
        }
        for (int j = 0; j < 5; j++) {
            a--;
        }
        System.out.println("Final value of a: " + a);
    }
}
  1. A.

    -5

  2. B.

    0

  3. C.

    5

  4. D.

    10

  5. E.

    None of the above

Attempted by 26 students.

Sign up free to check your answer

Sign up free

Explore the full course: Ibps So It Mains

Loading lesson…