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

public char[] replaced(char[] array, char oldChar, char newChar) Return a new ch

ID: 3584552 • Letter: P

Question

public char[] replaced(char[] array, char oldChar, char newChar) Return a new char[] that is a copy of array with all occurrences of oldChar replaced by newChar -- so replaced ({'A', 'B', 'C', 'D', 'B'}, 'B', '+') returns a new array {'A', '+', 'C', 'D', '+'}. The original array argument must remain unchanged. The returned array must have exactly the same capacity as the array reference passed to the parameter referenced as array. // The shortcut array arguments will not compile. // Declare an array outside of the method call and pass that array reference. replaced( { 'A', 'B', 'C', 'D', 'B'}, 'C', 'L' ) returns { 'A', 'B', 'L', 'D', 'B' } replaced( { 'n', 'n', 'n', 'D', 'n'}, 'n', 'T' ) returns { 'T', 'T', 'T', 'D', 'T' } replaced( { 'n', 'n', 'n' }, 'T', 'n' ) returns { 'n', 'n', 'n' }

Explanation / Answer

public char[] replaced(char[] array, char oldChar, char newChar){ char[] newArr= new char[array.length]; for(int i=0;i