Here is my code to reverse the elements in an array:
public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i=0; i < n; i++){
            arr[i] = in.nextInt(); 
        }
        int i=0;
        int j=n-1;
        int c;
        while(i<j){
            c=arr[i];
            arr[i]=arr[j];
            arr[j]=c;
            i++;
            j--;
        }
        System.out.println(arr[n]);
        in.close();
    }
}
The problem is my code is generating arrayIndexOutOfBound exception. How to remove it ?
 
     
     
     
     
     
    