How to define and initialize int array with the same number in Java

1 Answer

0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        int[] arr = new int[5];

        Arrays.fill(arr, 98);

        System.out.println(Arrays.toString(arr));
    }
}
 
 
 
/*
run:
 
[98, 98, 98, 98, 98]

*/

 



answered Jul 20, 2020 by avibootz

Related questions

1 answer 195 views
1 answer 182 views
1 answer 168 views
1 answer 228 views
1 answer 206 views
1 answer 179 views
...