Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*;
    public class Array_Examle
    {
    public static void main(String args[])
    {
    int p[] = new int [10];
    for (int k = 7; k > 0 ; k--)
    {
    p[7-k] = k;
    }
    Arrays.fill(p, 1, 4, 8);
    for (int k = 0; k < 5 ; k++)
    {
    System.out.print(p[k]);
    }
    }
    }
    1. 56885
    2. 678867
    3. 328832
    4. 78883
    5. 68883
Correct Option: D

array was containing 7,6,5,4,3,2,1 but when method Arrays.fill(array, 1, 4, 8) is called it fills the index location starting with 1 to 4 by value 8 hence array becomes 7,8,8,8,3.



Your comments will be displayed only after manual approval.