//This code is written by Siwat Sirichai public class Replace { public static int[] replace(int[] a, int v, int v2) { if (a==null)return a; //If a is a null pointer, return immediately to prevent a NullPointerException for(int i = 0; i < a.length;i++) //loop from 0 to the length of array a, number of completed iteration is stored in i (type int) if(a[i]==v)a[i]=v2; //if the value of a at index i is equal to v, replace it with v2 return a; //Return the replaced array a } public static void printArray(int[] a) { if(a==null) { System.out.println(); //Create a newline to make the format looks uniform return; //If a is a null pointer, return immediately to prevent a NullPointerException } //NOTE: return; (a return statement without a return value) in a method with no return type will break out of the method. for(int i = 0;i