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

 

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

For this problem, you are not allowed to use arrays, and the only string methods you are allowed to use are .equals, .length, .charAt, and .substring. Write a method that returns the number of times the single-character string 'ltr' occurs in a string 'str', except do not count 'ltr' if it occurs immediately after the single-character string 'exclude'. For example, in the string "this that then the other thing" if 'ltr' is "t" and 'exclude' is " " the method should return 3 since there are three occurrences of 't' that do not occur immediately after a space. Your method should be case-sensitive, so "t" and "T" are not considered the same character. As a pre-condition, you may assume that 'ltr' and 'exclude' will each contain exactly one character. Look at the test data!


nov9_2015_SLHL_countLetters("this that and the other thing", "t", " ") → 3
nov9_2015_SLHL_countLetters("once upon a time there was a bear of very little brain", "o", " ") → 2
nov9_2015_SLHL_countLetters("California ionic igloo ice", "i", "l") → 5

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

public int nov9_2015_SLHL_countLetters(String str, String ltr, String exclude) { }

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