4 Commits

  1. 17
      ArrayManipulation.java

17
ArrayManipulation.java

@ -13,6 +13,20 @@ public class ArrayManipulation {
return arr; return arr;
} }
public static int[] removeFirst(int[] arr) {
int length = arr.length;
int[] result = new int[length - 1];
for (int i = 1; i < arr.length; i++) {
result[i-1] = arr[i];
}
return result;
}
public static int [] removeLast(int[] arr) { public static int [] removeLast(int[] arr) {
int [] result = new int [arr.length-1]; int [] result = new int [arr.length-1];
@ -22,12 +36,13 @@ public class ArrayManipulation {
return result; return result;
} }
public static void main(String[] args) { public static void main(String[] args) {
int[] arr = {1,2,3,4,5}; int[] arr = {1,2,3,4,5};
System.out.println(Arrays.toString(reverseArray(arr))); System.out.println(Arrays.toString(reverseArray(arr)));
System.out.println(Arrays.toString(removeFirst(arr)));
System.out.println(Arrays.toString(removeLast(arr))); System.out.println(Arrays.toString(removeLast(arr)));
} }
} }
Loading…
Cancel
Save