about | help | code help+videos | done | prefs |
Given an input String, return the number of different characters present in the String. Thus, "abc" and "aaabbbc" will both return 3 because they all contain only 'a', 'b', 'c'. Precondition: str will only contain visible characters from the original ASCII subset (i.e. between values of 32 and 127). HINT: There are multiple ways to approach this problem. For example, you can use a loop likewhile(str.length() > 0)to keep looping as long as str has more characters to examine. You might consider using the replace() method of the String class to eliminate every character matching the first character of str from the output. Using replace looks like this: str.replace("a","") // evaluates to a version of str with no 'a' charactersAlso remember that a loop such as the one above will continue to operate even if the object referenced by str is replaced with a String with fewer characters... apcsaLoopsCharacterVariety("abc") → 3 apcsaLoopsCharacterVariety("aaabbbc") → 3 apcsaLoopsCharacterVariety("z") → 1 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 230
Copyright Nick Parlante 2017 - privacy