Surprise results

P

poonam

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 ;
ch ++ ;

}

int track [] = new int [10] ;


for (int i = 0 ; i < array.length ; i++)
{
int count = 0 ;
int control = 0 ;
String temp = array ;
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 = 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] ;
}
}
 
J

Jan =?UTF-8?B?VGhvbcOk?=

Hi,

i would strongly suggest, you have a look at this website:
http://catb.org/~esr/faqs/smart-questions.html

Especially pay attention to:

Use meaningful, specific subject headers
Write in clear, grammatical, correctly-spelled language
Be precise and informative about your problem
Volume is not precision
Describe the problem's symptoms, not your guesses
Describe your problem's symptoms in chronological order
Describe the goal, not the step
Be explicit about your question

Best regards,
Jan


poonam wrote:
[A ton of gibberish]
 
M

Manish Pandit

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 ...

The site (myjavaserver) runs your code through a series of tests. A
good program should be able to pass all the test conditions and/or
handle boundary conditions gracefully. When you test it on your local
system, it works because you are not hitting the boundary conditions,
or any other set of input that the site is using. Look at the output
where it shows the test data and the result. Use that data to test
your code.

Also, I am not sure if myjavaserver would appreciate posting solutions
to their challenge on newsgroups :)

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top