id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > nov4_SLHL_countMatches
prev  |  next  |  chance

Write a method that returns the number of times the 'target' string appears in the 'source' string. Overlaps are NOT allowed. For example, given 'source'="aaaaaa" and 'target'="aaa" your method must return 2 since there are two non-overlapping "aaa" strings within "aaaaaa". The only string methods you are allowed to use are .length, .substring, .equals, .compareTo, or .charAt. If you use a for-loop you must make sure you follow the conventions established in class... otherwise use a different kind of loop. Neither of the parameters will be an empty string. Note that the 'target' string could be longer than the 'source' string or vis-versa.


nov4_SLHL_countMatches("slip", "way to long") → 0
nov4_SLHL_countMatches("Hi", "i") → 1
nov4_SLHL_countMatches("aaaaaa", "aa") → 3

...Save, Compile, Run (ctrl-enter)

public int nov4_SLHL_countMatches(String source, String target) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 280

Copyright Nick Parlante 2017 - privacy