Wednesday, 25 February 2015

Filled Under:

How To Fill Values In Array Using Fill Method In Java

This tutorial illustrate how to fill values in array using fill() method in simple way.This method assign value to the array with a specified valued in array.It has two versions first version is shown here in this version specified value fill according to the given range by the user in this tutorial we fill 0 in 2 and 3 position it fill  values from start-1 position its constructor shown below
static void fill(int array[],int start,int end,int value)

CODING:

import java.util.*;
class arrayfill
{
public static void main(String args[])
{
int arr[] = {100,20,40,60,70,10};
System.out.println("Original Content:");
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
Arrays.fill(arr,1,3,0);
System.out.println("After Filling:");
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}

}
}

OUTPUT:


0 comments:

Post a Comment