1String line = "Your string here";
2String stringToCount = "?";
3int count = line.length() - line.replace(stringToCount, "").length();
1public static void main(String[] args) {
2 int wordCount = 0;
3 String word = "hill";
4 for (char letter = 'a'; letter <= 'z'; letter++) {
5 for (int i = 0; i < word.length(); i++) {
6 if (word.charAt(i) == letter) {
7 wordCount++;
8 }
9 }
10 if (wordCount > 0) {
11 System.out.println(letter + "=" + wordCount);
12 wordCount = 0;
13 }
14 }
15 }
1public class StringNumberOfOccurenceLetter {
2
3 private static int countOccurences(String word, char character){
4
5 int count = 0;
6 for (int i = 0; i < word.length() ; i++) {
7 if (word.charAt(i)==character){
8 count++;
9 }
10 }
11 return count;
12
13 }
14 public static void main(String[] args) {
15
16
17 int count = countOccurences("dddssad", 'a');
18 }
19
20
21}