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 274 views
1 answer 299 views
1 answer 256 views
1 answer 323 views
1 answer 303 views
1 answer 276 views
...