Both end array traversal

Approach

  public void bothEndArrayTraversal() {
        int[] arr = {5, 10, 15, 20, 25, 30};

        int start = 0;
        int end = arr.length - 1;

        while (start <= end) {
            if (start == end) {
                System.out.print(arr[start]);
            } else {
                System.out.print(arr[start] + " " + arr[end] + " ");
            }
            start++;
            end--;
        }
    }

Code Solution

Related video solution