Tuesday, February 16, 2010

Welcome To The Programme: Sample Need Help Simulating An IndexOf(); In A Java Program!?

Need help simulating an indexOf(); in a java program!? - welcome to the programme: sample

I have tried to solve this problem for hours and I can not understand how ... : (Kinda I could get a general idea, but I expect a proposal? In planning the program more.

(40 points) Write your own implementation of the method of the String class indexOf. More precisely, we write a program that simulates IndexOf.java the method of the String class. Your program will check two strings as arguments to the command line, and whether the second string is a string the first string. If the second string is a string, the program can be the index of its first appearance in print, otherwise it is -1 Pressure.
The only current methods of the String class is authorized to (but do not have to use them all) in this program are: Length (), charAt () or toCharArray ().
Example output (from several versions of the program):
> Java IndexOf "Welcome to Java, Java,
11
> Java IndexOf "Welcome to Java", "Java"
-1
> Java IndexOf "Coconut Peanut 'Pea"
8
> Java IndexOf "Coconut Peanut" nut "
4

1 comment:

Anonymous said...

Ok, since you do not directly use indexOf, you must use the network scanner and of course the substring () to verify the documents of the largest chain.

For example, the output of the first sample, you should focus on the search for the word java from scratch in the position of the "Welcome to Java". Since Java is the word is 4 letters, you can start SUBSTRING (0.4) to the search.

Then, with a loop, you can increase the values of 1.5 to 2.6 and then 3.7, etc. until you find the word you. If you are a little exhausted -1, otherwise you print the exact location of the beginning of the chain. You can determine what size is the word you are looking for with the extension. () Length method, of course.

Post a Comment