Lockpicking chef problem

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String args) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T>0){
int N = scan.nextInt();
int M = scan.nextInt();
M = Math.min(N,M);
scan.nextLine();
String s = scan.nextLine();
String k = scan.nextLine();
boolean replace = false;
if(k.contains(“0”))
replace=true;
k = k.replace(‘0’,‘9’);
int min = Integer.MAX_VALUE;
for(int i =0;i<s.length()+k.length()-1;i++){
if(i> s.length() - k.length()){
String sub = s.substring(i,s.length());
if(sub.length()==0)
break;
String t = s.substring(0,k.length()-sub.length())+sub;
min = Math.min(min,Math.abs(Integer.parseInt(t) - Integer.parseInt(k)));
}
else{
min = Math.min( min, Math.abs(Integer.parseInt(s.substring(i,i+k.length())) - Integer.parseInt(k)));
}
}
if(replace)
min+=1;
int sum =0;
while(min>0){
sum+=min%10;
min/=10;
}
System.out.println(sum);
T–;
}
// your code goes here
}
}
I know to know, why am I getting runtime error for above code? Please share sample test case, if possible

Same problem with me, i was executing this code in C++ and getting runtime error for one test case.