Arrays.fill(float[], float): This method is available in java.util.Arrays class of Java.
Syntax:
void java.util.Arrays.fill(float[] a, float val)
This method takes two arguments one of type float array and the other of type float as its parameters. This method assigns the specified float value to each element of the specified array of floats.
Parameters: Two parameters are required for this method.
a: the array to be filled.
val: the value to be stored in all elements of the array.
Returns: NA
Exceptions: NA
Approach
Java
import java.util.Arrays;public class Arraysfillfloat {public static void main(String[] args) {float a[] = new float[5];float val = 10;Arrays.fill(a, val);System.out.println(Arrays.toString(a));}}
Output:
[10.0, 10.0, 10.0, 10.0, 10.0]
No comments:
Post a Comment