Write a Java method: public static int[] transformArray(int[…
Write a Java method: public static int[] transformArray(int[] arr)that takes an array of integers as input and returns a new array where each element is replaced by the absolute difference between it and the next element in the array.For the last element, treat the next element as the first element (circular).Sample OutputInput array: {5, 3, 8, 2}1st element: |5 – 3| = 22nd element: |3 – 8| = 53rd element: |8 – 2| = 64th element: |2 – 5| = 3 (circular back to first)Output array: {2, 5, 6, 3}
Read Details