1public class CountStringOccurence {
2public static void main(String[] args) {
3
4int count= countOccurences("aaassssddadad",'s');
5System.out.println(count);
6
7}
8
9private static int countOccurences(String word, char character){
10
11 int count = 0;
12 for(int i = 0; i < word.length(); i++){
13
14 if(word.chartAt(i) == character){
15
16 count++; }
17 }
18 return count;
19}
20}
21
22
1public class CountStringOccurence {
2public static void main(String[] args) {
3
4int count= countOccurences("aaassssddadad",'s');
5System.out.println(count);
6
7}
8
9private static int countOccurences(String word, char character){
10
11 int count = 0;
12 for(int i = 0; i < word.length(); i++){
13
14 if(word.chartAt(i) == character){
15
16 count++; }
17 }
18 return count;
19}
20}
1#use the built in function len()
2
3len("hello")
4
5#or you can count the characters in a string variable
6
7a = "word"
8len(a)