Unable to run testcase1 for Last Index

Please let me know if did something wrong in my code

public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println(“Enter the length”); int n = sc.nextInt(); System.out.println(“Enter the number”); int num = sc.nextInt(); int arr[] = new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } System.out.println(printlastIndex(arr,num,0)); } public static int printlastIndex(int[] arr, int num, int si) { if(si == arr.length) { return -1; } int index = printlastIndex(arr, num, si+1); if(index ==-1) { if(arr[si]== num) { return si; } else { return -1; } } else { return index; } }

Only test case 1 is not passing? Because your logic is correct but you need to remove these unnecessary print statements and your input format is wrong. First N, then the array and then M.