Hausaufgabe 1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import java.util.Arrays;
  2. public class ArrayManipulation {
  3. public static int[] reverseArray(int[] arr, String test) {
  4. for (int i = 0; i < arr.length / 2; i++) {
  5. int tmp = arr[i];
  6. arr[i] = arr[arr.length - 1 - i];
  7. arr[arr.length - 1 - i] = tmp;
  8. }
  9. return arr;
  10. }
  11. public static int[] removeFirst(int[] arr) {
  12. int[] newArray1 = new int[arr.length -1];
  13. for (int i = 1; i < newArray1.length + 1; i++) {
  14. newArray[i - 1] = arr[i];
  15. }
  16. return arr;
  17. }
  18. public static int[] removeLast(int[] arr) {
  19. int[] newArray = new int[arr.length - 1];
  20. for (int i = 0; i < newArray.length; i++) {
  21. newArray[i] = arr[i];
  22. }
  23. return newArray;
  24. }
  25. public static void main(String[] args) {
  26. int[] arr = {1, 2, 3, 4, 5};
  27. System.out.println(Arrays.toString(arr));
  28. System.out.println(Arrays.toString(removeLast(arr)));
  29. System.out.println(Arrays.toString(reverseArray(arr, "Testing")));
  30. }
  31. }