getting time limit exceeded....new to code chef

I am new to code chef n i m getting time limit exceeded warning i need help on my code for the problem
http://www.codechef.com/problems/DEFACING-->
[1]: http://www.codechef.com/problems/DEFACING

``````
/*
description:converting a value to its maximum value acceptable according to its digital expression.
*/
import java.lang.*;
public class Main
{
private int n,temp,j,t1,k;
private Boolean flag,flag1,flag2,flag3;
java.io.PrintWriter out;
StringBuilder max,score;
java.util.StringTokenizer tokenizer;
private char nosConvertValues[][]={{'0','8'},
{'0','1','3','4','7','8','9'},
{'2','8'},{'3','8','9'},
{'4','8','9'},
{'5','6','8','9'},
{'6','8'},
{'0','3','7','8','9'},
{'8'},
{'8','9'}};
public static void main(String args[]) throws java.io.IOException
{
Main ms=new Main();
ms.init();
ms.out.close();
}
public void init() throws java.io.IOException
{
tokenizer = null;
out = new java.io.PrintWriter(System.out);
while(n-- > 0)
{
checking(max,score);
}
}
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
}
}
//converting the nos into the maximum score convertable
public void checking(StringBuilder max,StringBuilder score)
{
flag=false;
flag1=true;
flag2=false;
flag3=true;
t1=10;
for(j=0;j<score.length();j++)
{
temp=Integer.parseInt(score.charAt(j)+"");
if(flag)
{
max.setCharAt(max.length()-score.length()+j,nosConvertValues[temp][nosConvertValues[temp].length-1]);
}
else if(flag1)
{
flag3=false;
for(k=0;k<nosConvertValues[temp].length;k++)
{
if((int)nosConvertValues[temp][k]<=(int)max.charAt(max.length()-score.length()+j))
{
t1=(int)nosConvertValues[temp][k];
flag3=true;
}
else if(flag3==false)
{
max=GreaterNo(max,score);
}
}
if(t1<(int)max.charAt(max.length()-score.length()+j) && t1!=10)
{
flag=true;
max.setCharAt(max.length()-score.length()+j,(char)t1);
}
}
else if(flag2)
{
flag3=false;
for(k=0;k<nosConvertValues[temp].length;k++)
{
if((int)nosConvertValues[temp][k]<(int)max.charAt(max.length()-score.length()+j))
{
t1=(int)nosConvertValues[temp][k];
flag=true;
flag3=true;
}
else if(flag3==false)
{
max=GreaterNo(max,score);
}
}
if(t1<(int)max.charAt(max.length()-score.length()+j) && t1!=10)
{

max.setCharAt(max.length()-score.length()+j,(char)t1);
}
}
}
if(max.charAt(0)=='0' && max.length()>1)
{
max.deleteCharAt(0);
}
out.println(max.toString());
}
//If the Integer of the Location of the score has always higher value than the Integer of the Location of the maximum available
public StringBuilder GreaterNo(StringBuilder max,StringBuilder score)
{
if(j==0)
{
if(max.length()>score.length())
{
int temp1=Integer.parseInt(max.substring(0,max.length()-score.length()));
temp1--;
max.replace(0,max.length()-score.length(),temp1+"");
}
flag=true;
max.setCharAt(max.length()-score.length()+j,nosConvertValues[temp][nosConvertValues[temp].length-1]);
}
else
{
flag1=false;
flag2=true;
j--;
}
return max;
}
}

``````

the code runs fine on my pc n i have tested using the codechef method with 400000 cases and the time elapsed was 4 seconds so for the given criteria of the question it can’t exceed 2 seconds even as its in java so the timespan is extended to double so for the 200000 cases it cant exceed 4secs So whats the probm…