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

 

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

Write a method that counts how many times 'ltr' occurs in 'str'. Note that 'ltr' is a string, but it will always contain exactly one character. The string 'str' may contain any number of characters. Return a string that states how many times 'ltr' occurs. That string must be grammatically correct, so if it occurs exactly once you must end with "1 time.", but for any other number of times it should say "X times." (where X is the number of times it occurs). Look at the test data for examples.


test2021_04_22_APP1SLHL_countLtrs("This is a test", "t") → "The character t occurs 2 times."
test2021_04_22_APP1SLHL_countLtrs("jagsdsdauiygugauhgdgadgdshdgsa", "g") → "The character g occurs 7 times."
test2021_04_22_APP1SLHL_countLtrs("learning is so cool", "x") → "The character x occurs 0 times."

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

public String test2021_04_22_APP1SLHL_countLtrs(String str, String ltr) { }

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

Copyright Nick Parlante 2017 - privacy