Given:



class Test {

    int sum = 0;

    public void doCheck(int number) {
        if (number % 2 == 0) {
            break;
        } else {
            for (int i = 0; i < number; i++) {
                sum += i;
            }
        }
    }

    public static void main(String[] args) {
        Test obj = new Test();
        System.out.println("Red " + obj.sum);
        obj.doCheck(2);
        System.out.println("Orange " + obj.sum);
        obj.doCheck(3);
        System.out.println("Green " + obj.sum);
    }
}

What is the result?

A.

Red 0
Orange 0
Green 3

B.

Red 0
Orange 0
Green 6

C.

Red 0
Orange 1

D.

Green 4

E. Compilation fails

題解

「break;」敘述只能用在迴圈和「switch」結構中,因此這題會編譯錯誤。