X906: makeAndInit

Write a method that takes two arguments, the first is an integer size and the second argument, init, is a default value to use to initialize all elements of a new array. The method should allocate a new array of int with size number of elements and then initialize all elements with the default value `init. Then return the newly created and initialized array.

Examples:

makeAndInit(3, 5) -> {5, 5, 5}
makeAndInit(2, 75) -> {75, 75}

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.