Divisible BY 8

This is my Code
Scanner in = new Scanner(System.in);
List list = new ArrayList<>();
for(int i=1;i<=125;i++) list.add(“”+8*i);
int t=in.nextInt();
for(int idx=0;idx<t;idx++)
{
double n=in.nextDouble();
String s=in.next();
double len=s.length();
if(len==1){
System.out.println(8);
}
else if(len<3){
if(Integer.parseInt(s)%8==0) System.out.println(s);
else {
String ans=“”;
int min=Integer.MIN_VALUE;
for(int i=1;i<12;i++){
int cnt=0;
String a=s;
String b=list.get(i);
for(int j=0;j<2;j++) {
if(a.charAt(j)==b.charAt(j)) cnt++;
}
if(min<cnt){
min=cnt;
ans=b;
}
}
System.out.println(ans);
}
}
else {
String sub=s.substring((int)len-3);
if(Integer.parseInt(sub)%8==0){
System.out.println(s);
} //299792458196831048576
else {
//System.out.println(sub);
String ans=“”;
int min=Integer.MIN_VALUE;
for(int i=12;i<list.size()-1;i++){
int cnt=0;
String a=sub;
String b=list.get(i);
for(int j=0;j<3;j++) {
if(a.charAt(j)==b.charAt(j)) cnt++;
}
if(min<cnt){
min=cnt;
ans=b;
}
}
System.out.println(s.substring(0,(int)len-3)+ans);
}
}
I still wonder whats throwing me Error !
Can somebody help me with this ?

To be honest, I’m not good at Java. But I can firmly say, this may help you

codechef.com/viewsolution/1025297287
I have solved this problem in python. You may visit here. There, I explained this problem. I think, that would be helpful))