Answers for "count number of occurrences of character in string"

2

count characters in string python

>>> sentence = 'Mary had a little lamb'
>>> sentence.count('a')
4
Posted by: Guest on December-30-2020
-1

count 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
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
0

check how many letters in a string python

#use the built in function len()

len("hello")

#or you can count the characters in a string variable

a = "word"
len(a)
Posted by: Guest on April-09-2020

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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language