Assigns the specified int value to each element of the specified array of ints.
Line | Description |
---|---|
5 | Declaration and initialization of the array myArray with the values 6, 4, 9, 1, 3 and 7. |
7 | The fill() assigns the specified int value (1) to each element of myArray |
9 – 11 | With a for loop, each array element is output by specifying the index. |
import java.util.Arrays;
public class ArrayMethods {
public static void main(String[] args) {
int[] myArray = { 6, 4, 9, 1, 3, 7 };
Arrays.fill(myArray, 1);
for (int i = 0; i < myArray.length; i++) {
System.out.print(myArray[i] + " ");
}
}
}
1 1 1 1 1 1