Browse Source

Version 2.1

master
Marc Leuschner 3 years ago
parent
commit
6268a8125d
  1. 55
      src/ArrayManipulation.java

55
src/ArrayManipulation.java

@ -1,31 +1,27 @@
import java.util.Arrays;
public class ArrayManipulation {
public static int[] reverseArray(int[] arr) {
for (int i = 0; i < arr.length/2; i++) {
int tmp = arr[i];
arr[i] = arr[arr.length - 1 - i];
arr[arr.length - 1 - i] = tmp;
}
return arr;
}
}
public static int[] removeFirst(int[] arr) {
if (arr == null || arr.length==0) {
int[] result = new int[0];
return result;
}
if(arr.length == 1||arr.length == 0) {
return arr;
}
int[] result = new int[arr.length-1];
for(int a=1;a<arr.length;a++) {
result[a-1] = arr[a];
}
}
if(arr.length == 1||arr.length == 0) {
return arr;
}
int[] result = new int[arr.length-1];
for(int a=1;a<arr.length;a++) {
result[a-1] = arr[a];
}
return result;
}
@ -33,28 +29,27 @@ public class ArrayManipulation {
if (arr == null || arr.length==0) {
int[] result = new int[0];
return result;
}
if(arr.length == 1||arr.length == 0) {
return arr;
}
if(arr.length == 1||arr.length == 0) {
return arr;
}
int[] result = new int[arr.length-1];
for(int a=0;a<arr.length-1;a++) {
result[a] = arr[a];
}
return result;
int[] result = new int[arr.length-1];
for(int a=0;a<arr.length-1;a++) {
result[a] = arr[a];
}
return result;
}
public static int[] squareEach(int[] arr) {
if (arr == null || arr.length==0) {
int[] result = new int[0];
return result;
}
int[] result = new int[arr.length];
int[] result = new int[0];
return result;
}
int[] result = new int[arr.length];
for(int a=0;a<arr.length;a++) {
result[a] = arr[a] * arr[a];
}
return result;
result[a] = arr[a] * arr[a];
}
return result;
}
public static void main(String[] args) {

Loading…
Cancel
Save