about | help | code help+videos | done | prefs |
Given an input String str, determine if searchWord exists as its own word in the input. For this problem, a word means any characters that are surrounded by spaces, or are at the beginning of the input (space after, starts at 0), or the end of the input (space before, ends at str.length() - 1). Precondition: str will contain only capital letters and spaces (no punctuation or other characters), and searchWord will contain only capital letters. HINT: You will need to check for searchWord at the beginning and end of str, as well as in the middle. Most students will probably use three if statements to address these three possibilities. CHALLENGE: for advanced students, you can also do this by using split() and a for loop. (requires arrays) Or you can use a while loop that looks over and over again for the next occurrence of searchWord within str. CHALLENGE: for really advanced students, solve this problem using a Scanner, regular expressions or stream processing. CHALLENGE (actually not that hard): solve this in one statement.apcsaChatbotsWordExists("SAM I AM", "I") → true apcsaChatbotsWordExists("SAM I AM", "SA") → false apcsaChatbotsWordExists("SAM I AM", "SAM") → true ...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: 210
Copyright Nick Parlante 2017 - privacy