Surprise results
Hi every1
Please visit the following link :
http://www.myjavaserver.com/signup
for becoming member u have to make the code which I did as
follows ...
It works well when I run it like ne other program on my system
but when I execute through there < myjavaserver.com > , it gives
me different result as in .... output is for 2 strings instead of one
which has the maximum value for count variable
how do I rectify the problem, do I need to modify the
logic ??........ dnt go by size of code , it's
just made up o basic stuff
thanks
poonam
public class search
{
public static void main(String[] args) {
search sea = new search () ;
String config [] = { "/", "TestServlet", "/test",
"TestServlet2" } ;
String requestUri = "/te" ;
sea.getHandler(config , requestUri) ;
}
public String getHandler(String[] config, String requestUri)
{
int ch = 0 ;
int len = config.length ;
String array [] = new String [len/2] ;
for (int s = 0 ; s < config.length ; s = s + 2)
{
array [ch] = config [s] ;
ch ++ ;
}
int track [] = new int [10] ;
for (int i = 0 ; i < array.length ; i++)
{
int count = 0 ;
int control = 0 ;
String temp = array [i] ;
if (requestUri.length () > temp.length () )
{
control = temp.length () ;
}
else
{
control = requestUri.length () ;
}
for (int j = 0 ; j < control ; j ++)
{
if (requestUri.charAt (j) == temp.charAt(j))
{
count ++ ;
}
}
track [i] = count ;
}
int find = track[0] ;
for (int k = 0 ; k < track.length ; k++)
{
find = Math.max(find,track[k]);
}
System.out.println("No of characters matched : " + find) ;
int temp = 0 ;
for (int k = 0 ; k < track.length ; k++)
{
if (find == track[k])
{ temp = k ;
break ;
}
//System.out.println (track[k]) ;
}
System.out.println("Index number: " + temp) ;
int go = 0 ;
if (temp == 0)
{go = 1 ; }
if (temp == 1)
{go = 3 ; }
System.out.println(config [go]) ;
return config [go] ;
}
}