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.

31 lines
703 B

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