|
@ -16,12 +16,12 @@ public class ArrayManipulation { |
|
|
|
|
|
|
|
|
public static int[] removeLast(int[] arr){ |
|
|
public static int[] removeLast(int[] arr){ |
|
|
int arr2[]; |
|
|
int arr2[]; |
|
|
if(arr.length<=1) return arr2 = new int[0]; //Falls Array nur eine oder weniger Elemente hat,leeres Array zurückgeben |
|
|
|
|
|
arr2 = new int[arr.length-1]; //Sonst neues Array mit einem Element weniger erstellen |
|
|
|
|
|
|
|
|
if(arr.length<=1) return arr2 = new int[0]; //if array only has 1 elements, give empty array |
|
|
|
|
|
arr2 = new int[arr.length-1]; //else make new array with length one less |
|
|
for(int i=0; i<arr.length-1; i++){ |
|
|
for(int i=0; i<arr.length-1; i++){ |
|
|
arr2[i]=arr[i]; //Kopieren der Elemente des Original Array |
|
|
|
|
|
|
|
|
arr2[i]=arr[i]; //copy all but the last elements of original array |
|
|
} |
|
|
} |
|
|
return arr2; //Neues Array zurückgeben |
|
|
|
|
|
|
|
|
return arr2; //return new array |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|