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.

38 lines
939 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 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. int[] arr = {1,2,3,4,5,8};
  14. System.out.println(Arrays.toString(reverseArray(arr)));
  15. }
  16. public static int[] removeFirst(int[] arr) {
  17. int[] newArray = new int[arr.length];
  18. for(int i = 1; i < arr.length; i++){
  19. newArray[i-1] = arr[i];
  20. }
  21. return newArray;
  22. }
  23. public static int[] removeLast(int[] arr) {
  24. int[] result = new int[arr.length-1];
  25. for (int i = 0; i < arr.length-1; i++) {
  26. result[i] = arr[i];
  27. }
  28. return result;
  29. }
  30. }