Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Surprise results

Thread view: 
poonam - 22 Aug 2007 20:38 GMT
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] ;
 }
}
Jan Thomä - 22 Aug 2007 20:50 GMT
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

[A ton of gibberish]
Signature

_________________________________________________________________________
insOMnia - We never sleep...
http://www.insOMnia-hq.de

Manish Pandit - 22 Aug 2007 22:29 GMT
> Hi every1
>
[quoted text clipped - 4 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.