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

 

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

Your goal is to return the number of times that the 'target' letter appears in the string 'str'. You will only check the characters of str until you get to 'stopAt' number of characters. Sometimes stopAt will be greater than the number of characters in str. In that case check all the characters in str. For example: runCount("abcdebebabbbbbb", 'b', 6) returns 2 because in the first 6 characters of str 'b' appears twice. However, runCount("abcdebebabbbbbb", 'b', 56) returns 9. Since 56 was more than the number of characters in the string, we end up checking all the characters, and 'b' appears 9 times. You have a restricted set of string commands for this problem. The only string commands you are allowed to use are: .charAt .substring .length and .equals. No other string commands may be used.


runeCount("You don't need to see his identification.", "o", 50) → 4
runeCount("These aren't the droids you're looking for.", "o", 29) → 2
runeCount("That's no moon. It's a space station.", "a", 50) → 4

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

public int runeCount(String str, char target, int stopAt) { }

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: 250

Copyright Nick Parlante 2017 - privacy