I WANT TO REVERSE AN ARRAY

    Scanner input=new Scanner(System.in);
    int n =input.nextInt();
    int i,a;
    int[] arr = new int[n];
    a=n-1;
    int[] ary=new int[n];
    for(i=0;i<n;i++){
        arr[i]=input.nextInt();
        if(i==a){
            ary[a]=arr[i];
            a--;
            i=i-2;
        }
    }
    for(i=0;i<n;i++){
        System.out.print(ary[i]+" ");
    }

Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Solution.main(Solution.java:21

@KUNAL.SHARMA5724510
you first need to put the testcase in the box below compile and run button and click on it.
otherwise you will get this error.

i given input but still error. please correct my code.

@KUNAL.SHARMA5724510
here is the code to reverse an array
Scanner input=new Scanner(System.in);
int n =input.nextInt();
int i,a;
int[] arr = new int[n];
a=n-1;
int[] ary=new int[n];
for(i=0;i<n;i++){
arr[i]=input.nextInt();
ary[a]=arr[i];
a–;

    }
    for(i=0;i<n;i++){
        System.out.print(ary[i]+" ");
    }

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.