Ok guys, I've tried everthing thing I can think of. I even went to see the
teacher for help. I am almost there I can feel it. I just can't get the last
word to return. If anyone could help that would be great and much
appreaciated
public class split {
public static void main(String [] args){
System.out.println("Please enter 3 words, followed by a space between each
word. ");
String input;
input = Stdin.readln(); // Read input from console.
int blank1 = input.indexOf(" ");
String word1= input.substring(0, blank1); // Finds first word in sentence.
String rest = input.substring(blank1+1, input.length());//** both words on
new line*****
int blank2 = rest.indexOf(" ");
String word2 = rest.substring(0, blank2); // Finds second word in sentence.
String foo = input.substring(blank2+1,input.length());
String word3= foo.substring(0);
System.out.println("\n" + word1+ "\n" + word2 + "\n" + word3);
jessu - 28 Sep 2005 05:06 GMT
Replace the last few lines:
>>String foo = input.substring(blank2+1,input.length());
String foo = rest.substring(blank2+1,rest.length());
>> String word3= foo.substring(0);
This is not needed... foo contains the last word
----------
FeedFeeds : A new way to read news and blogs!
http://www.feedfeeds.com
Hal Rosser - 30 Sep 2005 01:37 GMT
Take a look at the split method of String
it may help and could be a little less clumsy.
hope this helps
Roedy Green - 30 Sep 2005 07:04 GMT
>Take a look at the split method of String
>it may help and could be a little less clumsy.
>hope this helps
The split method in String necessarily compiles the pattern every time
you use it. If you use the Pattern version you need compile it only
once in a static init. Compiling a pattern is a non-trivial operation.
It is hardly any more work to do it properly. It also lets you put
all your patterns side by side in the declarations where there are
easy to compare and maintain.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.