RUN error while submission of a particular test case

While submitting the code, it’s showing RUN ERROR in Test case 0, but test case 1 and 2 are successfully passed. Please resolve.

My Code is as follows:-

import java.util.;
import java.io.
;
public class Main {

public static int lastIndex(int[] arr, int n, int i, int key){
	if(i==n){
		return -1;
	}
	int index = -1;
	if(arr[i]==key){
		index = lastIndex(arr, n, i+1, key);
		if(index<i){
			index = i;
		}
	}
	else 
		index = lastIndex(arr, n, i+1, key);
	return index;
}
public static void main(String args[]) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(br.readLine());
	StringTokenizer st = new StringTokenizer(br.readLine());
	int[] arr = new int[n];
	for(int i=0; i<n; i++){
		arr[i]= Integer.parseInt(st.nextToken());
	}
	int m = Integer.parseInt(br.readLine());
	System.out.println(lastIndex(arr, n ,0 ,m));
}

}

for test case:
7
45 -16 77 65 45 77 45
45
ans 7 you are getting 6
debug for this

I am getting 6 for this test case and 6 is the correct answer as well. The question asks us to find last index and for this test case last index of 45 is 6.

yes my bad
First you need to trim your string before trying to parse it like
int n = Integer.parseInt(br.readLine().trim());
you can see this


to avoid this you can simply follow this without employing any buffer reader