Skip to content

Instantly share code, notes, and snippets.

@nhomble
Created August 24, 2022 01:07
Show Gist options
  • Save nhomble/ed850b0c3c0da05abaaebad4b4fcf90d to your computer and use it in GitHub Desktop.
Save nhomble/ed850b0c3c0da05abaaebad4b4fcf90d to your computer and use it in GitHub Desktop.
public class ExampleLoopString {
public static int frequencyOf(String input, char c) {
if (input == null) {
return 0;
}
int ret = 0;
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == c) {
ret += 1;
}
}
return ret;
}
public static void main(String[] args) {
System.out.println(frequencyOf("abcd", 'd'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment