Question: 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

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
,
7
5
)
-
>
{
7
5
,
7
5
}
Current code:
public int[] makeAndInit(int size, int init)
{
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!