What is the explanation for the following question

0

This is a java certification simulation issue at Whizlabs.

public class Whizlabs {
    public static void main(String[] args) {
        int[] testData = {1, 2, 3};
        for(abc){
        }
    }
}

The question is: "Choose the option to replace the text" abc "in the above code." (Select 2 options)

A. int i : testData

B. int i = 0; i < 1; i++

C. i++

D. ;i++; 1 < 1;

E. ;i < 1; 0

The correct answer is the letter "A" and "B". Because? I did not understand the answer.

    
asked by anonymous 14.05.2017 / 04:10

1 answer

1

The answer is the letter A. What you want is to iterate through the array.

int[] testData = {1, 2, 3};
for(int i : testData){
     System.out.println(i);
}

It's the same thing to do:

int[] testData = {1, 2, 3};
for(int i = 0; i < 3; i++){
     System.out.println(i);
}
    
16.05.2017 / 18:01