Write a recursive method public static void replaceMult5int

Write a recursive method public static void replaceMult5(int[] nums, int newVal) that replaces all multiples of 5 in the nums array with the argument newVal. Make no other changes to the array.

Method Call : New Contents of nums

replaceMult5(new int[]{5,3,5,50,2,4,6,60}, 77) : {77, 3, 77, 77, 2, 4, 6, 77}

replaceMult5(new int[]{5,3,-5,50,2,4,6,-60}, 99) : {99, 3, 99, 99, 2, 4, 6, 99}

replaceMult5(new int[]{4,3,-8,33,2,4,6,-61}, 44) : {4, 3, -8, 33, 2, 4, 6, -61}

Note: You are not permitted to use any loops whatsoever in writing this method! You may write helper methods if you like, but those methods must not contain any loops either.

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

----------------------------------------------------------------

OUTPUT:

[77, 3, 77, 77, 2, 4, 6, 77]
[99, 3, 99, 99, 2, 4, 6, 99]
[4, 3, -8, 33, 2, 4, 6, -61]

Write a recursive method public static void replaceMult5(int[] nums, int newVal) that replaces all multiples of 5 in the nums array with the argument newVal. Ma

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site