Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a recursive method public static void replaceMult5(int[] nums, int newVal)

ID: 3777621 • Letter: W

Question

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.

Explanation / Answer

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]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote