Menu
Topics Index
...
`

Array filling and printing


If you need explanation Read this topic

If you need Answer Take test on this topic

Array filling and printing
What will be the output of the following program?
import java.util.*;

public class ArrayInitialize
{
    public static void main(String args[])
    {
        int array[] = new int[6];
        Arrays.fill(array, 100);

        for (int i = 0, n = array.length; i < n; i++)
        {
            System.out.print(array[i] + " ");
        }
        System.out.println();

        Arrays.fill(array, 3, 6, 50);
        for (int i = 0, n = array.length; i < n; i++)
        {
            System.out.print(array[i] + " ");
        }
    }
}

A. 100 100 100 100 100 100 
100 100 100 100 100 100
B. 100 100 100 100 100 100 
100 100 100 50 50 50
C. 100 100 100 100 100 100 
100 100 100 50 100 50
D. 100 0 0 0 0 0 
3 6 50 0 0 0
E. Compilation Error or Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans B Array.fill(arrayname ,starting index ,ending index ,value) method of Java Util class.

Posted by Bheema Reddy    2014-02-20 12:58:52


Ans is B
first for loop
Array.fill(array,100); //fills all the elements of the array with 100
second for loop
Array.fill(array,startindex,lastindex,value)//fills the array ranging from start index(including) and lastindex(excluding) with value i.e 50

Posted by Kittu Manoj    2014-02-20 12:59:35


Congratulations Kittu Manoj. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-02-21 05:36:37


© meritcampus 2019

All Rights Reserved.

Open In App