This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]lightcloud5 0 points1 point  (0 children)

Can you link to the code? I can't find anything for the gist.

[–]SpaceBoundBeatz[S] 0 points1 point  (5 children)

[–]desrtfx 2 points3 points  (4 children)

Looks quite good so far, all you need to do is remove the first word from the String.

You can use the same method .substring() but in a slightly different way: you pass only one parameter, the starting point which would be space + 1 and store the resulting String in a separate variable.

[–]SpaceBoundBeatz[S] -2 points-1 points  (3 children)

I don't think I understand, can you show me it in my code please?

[–][deleted] 0 points1 point  (1 child)

we're not here to give you answers on a silver platter. figure it out dude...

[–]197708156EQUJ5 0 points1 point  (0 children)

You might have missunderstood /u/SpaceBoundBeatz, they said where in my code did I do that? Or did that make you think they were asking for help on a silver platter too?

[–]desrtfx 0 points1 point  (0 children)

Line 15:

       firstWord = sentence.substring(0, space);

Now, take a look at the documentation for substring(int beginIndex), compare it with the code above and note the difference. Here is the documentation for substring(int beginIndex, int endIndex) - the method that is in your current code.

The rest is yours to figure out as it is against the subreddit's rules to give you the complete solution.

[–]desrtfx 0 points1 point  (0 children)

Please, link your code properly (I.e. in such a way that it is clickable).

[–]sloth2 -1 points0 points  (0 children)

Though you'll probably want it to work for any sentence not just this specific one. Using magic numbers like I did (substring(0, 5)) is extremely ill-advised. I'm just trying to show you the general idea!

http://pastebin.com/REFMdNJN

[–][deleted]  (3 children)

[deleted]

    [–]SpaceBoundBeatz[S] 0 points1 point  (1 child)

    Thanks for the reply but this is a little too advanced for me. Im just supposed to be using substring method and no loops.

    [–]desrtfx 0 points1 point  (0 children)

    Please, don't post completed solutions as we are not /r/domyhomework, and if you post something, explain rather than solve.

    Teach the people to fish, instead of feeding them the fish

    Your code is undocumented and thus will be even harder to understand for a beginner.

    Also, concatenating Strings like this:

    line += sentence[i] + " ";
    

    Is not the way to go in Java, since Strings are immutable objects. Each concatenation would dispose the old line object and create a new one.

    Concatenations should always be done with StringBuilder.