ArrayManipulation
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

43 lines
1.1 KiB

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