Java OCA OCP Practice Question 2736

Question

Given the following declaration of an array, which statement will display each element of the array?

int arr[] = {1,2,3,4,5};
a.  for(int n : arr[]) { System.out.println(n);   }

b.  for(int n : arr) { System.out.println(n);   }
c.  for(int n=1; n < 6; n++) {  System.out.println(arr[n]);
    }

d.  for(int n=1; n <= 5; n++) {  System.out.println(arr[n]);
    }


b, c, and d

Note

You cannot use [] in a for-each statement.




PreviousNext

Related