I wrote the program below but the print statement at the last is not printing anything
I have tried to check wether the value to be prited is null
this problem is from codechef here is the question, plz help me
public class Main{
public static void main(String args[]){
try{
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
int ans[]=new int[T];
for(int i=0;i<T;i++){
int n=sc.nextInt();
int a[]=new int[n];
int d[]=new int[n];
int gsv=0;
for(int j=0;j<n;j++){
a[j]=sc.nextInt();
}
for(int j=0;j<n;j++){
d[j]=sc.nextInt();
}
for(int j=0;j<n;j++){
int ha1;
int ha2;
int hd;
if(j==0) {
ha1=a[n];
ha2=a[j+1];
hd=d[j];
if(hd>ha1 && hd>ha2){
if(hd>gsv){
gsv=hd;
}
}
}
else if(j==n-1){
ha1=a[j-1];
ha2=a[0];
hd=d[j];
if(hd>ha1 && hd>ha2){
if(hd>gsv){
gsv=hd;
}
}
}
else{
ha1=a[j-1];
ha2=a[j+1];
hd=d[j];
if(hd>ha1 && hd>ha2){
if(hd>gsv){
gsv=hd;
}
}
}
}
ans[i]=gsv;
}
for(int i=0;i<T;i++){
if(ans[i]==0){
System.out.println("-1");//not printing
}else{
System.out.println(ans[i]);//not printing
}
}
}catch(Exception e){
}
}
}
expected input:
1
4
1
1
4
1
3
4
2
1
expected output:
3
current output:
//nothings printedenter code here