- 1
WAP to count a char appeared in given string
3 odpowiedzi
+ 8
With Java8:
String str = "abcdabcd";
char c = 'a';
long count = myString.codePoints().filter(ch -> ch ==c).count();
+ 1
public int charCount(String str,char c){
int x=0
for(int i=0;i<str.length();i++){
if( str.charAt(i)==c)
x++;
}
return x;
}
0
thnx