about | help | code help+videos | done | prefs |
HARDER PROBLEM: skip if you have troubleGiven an input String, find and return the last word in the input. A word always ends in a letter, and after the letter is zero or more periods, followed by zero or more spaces unless the word is the end of the String. So "don't" is actually a word for this purpose, but not "teachers'" (apostrophe at the end means it isn't a letter). "blah." is a word ending in the period, for which this method should just return "blah". Precondition: the input will have at least one word. HINT: use Character.isLetter(str.charAt(index)) to find out the location of the last letter. You probably need to use a loop from the back, unless you are being all fancy. Super-advanced challenge: what is the minimum number of statements you can use to solve this? apcsaChatbotsLastWordHard("We are the world") → "world" apcsaChatbotsLastWordHard("We are the world.") → "world" apcsaChatbotsLastWordHard("We are. the world") → "world" ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 360
Copyright Nick Parlante 2017 - privacy