play with strings

I’m getting a runtime error. But when I compile it with custom input it works.

import java.io.*;
class play
{
int l1,l2;
String s1,s2;
char A[]=new char[100];
char B[]=new char[100];
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void main()throws IOException
{
int t;
t=Integer.parseInt(br.readLine());
while(t–>0)
{
s1=br.readLine();
s2=br.readLine();
s1=s1.toLowerCase();
s2=s2.toLowerCase();
arr();
check();
}
}
void arr()
{
l1=s1.length();
l2=s2.length();
for(int i=0;i<l1;i++)
{
A[i]=s1.charAt(i);
}
for(int i=0;i<l2;i++)
{
B[i]=s2.charAt(i);
}
}
void check()
{
int j=0,count=0,c2=0;
for(int i=0;i<l1;i++)
{
if(A[i]==B[j])
{
count++;
j++;
}
}
j=0;
for(int i=(l1-1);i>=0;i–)
{
if(A[i]==B[j])
{
c2++;
j++;

          }
        }
      if((count==l2)&&(c2!=l2))
      {
          System.out.println(1);
      }
      else
       if((count!=l2)&&(c2==l2))
       {
          System.out.println(2);
       }    
       else
        if((count==l2)&&(c2==l2))
        {
          
          System.out.println("3");
        }
        else
            System.out.println("0");
    }
public static void main(String args[])throws IOException
{
    play ob=new play();
    ob.main();
   
}

}

It’s a humble request to put your code in proper blocks with comments if possible, or give ideone link. I don’t mean to offend you but don’t you think the readability is very poor?

1 Like

Firstly, your code shows numerous compilation errors on Ideone. I don’t know how the same code works on your compiler.

Your code probably throws an exception which should be caught. More about NZEC NZEC Error