Hi guys, I'm kind of stuck on a problem I was assigned.
Pretty much we're trying to reverse words in a sentence.
As in, input = Hi I am new to Java
to:
Java to new am I Hi
I've tried this
String[]Tyler = new String[Sentence.length()];
Tyler[0] = Sentence;
for(int i=0;i<Sentence.length();i++)
{
if(Position[i] == -1)
{
break;
}
else
{
Position[i] = Tyler[i].indexOf(" ");
Tyler[i+1] = Tyler[i].substring(Position[i]+1);
count = count + 1;
}
}
for(int i=0;i<4;i++)
{
System.out.println(Tyler[i]);
}
System.out.print(count);
*/
And all that would do is simply COUNT the words. I would then have to find each individual word, place it into the array, reverse the array.
That's where I'm having trouble.
I cannot import ANYTHING. Has to be done with just basic EasyReader to read in the input and that's it.
I can use as many arrays as I want.
My idea was to find the first space and then by finding that space, I have my first word.
my first word would be:
Position[0] = Sentence.indexOf(" ");
Sentence.substring(0,Position[0]);
But I'm not sure where to work from there.
I don't really want the full solution, just how to get there.