this class is a test to see if my 2 methods (the "endfinder"s) are working (unfortunately they are not). endfinder() is meant to return the index of the next non space character in the provided string; endfinder2() is meant to return the endpoint of the word starting with the index found by endfinder. They're meant to be used to pull out words from a string with multiple words separated by spaces. I've gone over it for a few hours and there must be some obvious answer but I feel like I'm slowly going insane.
I've removed all of the outputs I used to test the code in many attempts to figure out what was wrong to make it cleaner.
Basically, what I've found is that endfinder() always returns 0 for some reason and endfinder2() runs until it reaches the break (I assume that's what happens as it used to loop infinitely before I added it in).
The result I want is start = 3, end = 6 which would make it output "[one]".
The result I get:
[ one two three] start = 0, end = 17.
Here's my code:
import java.io.*;
import java.util.*;
public class test {
static String answer, container;
static int start = 0, end = 1;
public static int endfinder(String perspective) {
int holder = start;
while (perspective.substring(holder, (holder + 1)) == " ") {
holder++;
if (holder == perspective.length())
break;
}
return holder;
}
public static int endfinder2(String perspective) {
int holder = end;
while (perspective.substring(holder, (holder + 1)) != " ") {
holder++;
if (holder == perspective.length())
break;
}
return holder;
}
public static void main(String Args[]) {
System.out.println();
System.out.println();
container = " one two three";
start = endfinder(container);
end = start + 1;
end = endfinder2(container);
System.out.println("[" + container.substring(start, end) + "]");
System.out.println();
System.out.println("start: [" + start + "] end: [" + end + "]");
System.out.println();
}
}