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

 

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

Write a method with the following pre-conditions: str will contain a string that may be empty. toCount will contain a single character which may or may not appear in str. unless will contain a single character which may or may not appear in str. The method returns the number of times the character in toCount appears in str, except that the character in toCount is NOT counted if it comes immediately after the character in unless. For example: countLettersUnless("all fly last",'l','f') will return 3 because the letter 'l' appears 4 times, but one of those times it comes right after an 'f', so that one is not counted.


countLettersUnless("once upon a time there was a computer", "z", "u") → 0
countLettersUnless("once upon a time there was a computer", "e", "r") → 4
countLettersUnless("lfkasjdjhadsouweorifuadslfikjgd", "r", "i") → 1

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

public int countLettersUnless(String str, char toCount, char unless) { }

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

Copyright Nick Parlante 2017 - privacy