Check out example codes for "fix45 codingbat solution". It will help you in understanding the concepts better.

Code Example 1

public int[] fix45(int[] nums) {
  for (int i=0;i<nums.length;i++){
    if (nums[i]==4){
      int temp=nums[i+1];
      nums[i+1]=143;
      for (int j=0;j<nums.length;j++){
        if (nums[j]==5){
          nums[j]=temp;
        }
      }
      
    }
  }
  for (int i=0;i< nums.length;i++){
      if (nums[i]==143){
       nums[i]=5;
      }
  }
  return nums;
}
/// Thank You

Learn ReactJs, React Native from akashmittal.com