Answers for "number of occurrences of character in string"

0

number of occurrences of character in string

public class CountStringOccurence {
public static void main(String[] args) {

int count= countOccurences("aaassssddadad",'s');
System.out.println(count);

}

private static int countOccurences(String word, char character){
  
  int count = 0;
  for(int i = 0; i < word.length(); i++){
    
    if(word.chartAt(i) == character){
      
      count++; } 
                 }
      return count;
}
}
Posted by: Guest on January-22-2021

Code answers related to "number of occurrences of character in string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language