Java Array class fill(float[] a, int fromIndex, int toIndex, float val) example
Array class fill(float[] a, int fromIndex, int toIndex, float val) method example
Array class fill(float[] a, int fromIndex, int toIndex, float val) method example. This example shows you how to use fill(float[] a, int fromIndex, int toIndex, float val) method.This method Assigns the specified float value to each element of the specified range of the specified array of floats.
Here is the code:-
/**
* @Program that Assigns the specified float value to each element of the
* specified range of the specified array of floats.
* fill9Array.java
* Author:-RoseIndia Team
* Date:-16-May-2008
*/
import java.util.*;
public class fill9Array {
public static void main(String[] args) {
//creating a float array
float b[] = {12.98f,3.56f,4.56f,67.6f,89,98};
System.out.print("The original array is:-");
for (int i = 0; i < b.length; i++) //Display the float array
{
System.out.print("\t"+b[i]);
}
System.out.println();
// Assigns the specified float value to each element of the
//* specified range of the specified array of floats.
Arrays.fill(b,0,6,100.9f);
System.out.print("The Changed array is:-");
for (int i = 0; i < b.length; i++)
//Display the Changed float array
{
System.out.print("\t"+b[i]);
}
}
} |
Output of the program:-
The original array is:- 12.98 3.56 4.56 67.6 89.0 98.0
The Changed array is:- 100.9 100.9 100.9 100.9 100.9 100.9 |
|