- 1

WAP to count a char appeared in given string

6th Mar 2017, 7:56 PM
Kashish Gupta
Kashish Gupta - avatar
3 Respostas
+ 8
With Java8: String str = "abcdabcd"; char c = 'a'; long count = myString.codePoints().filter(ch -> ch ==c).count();
6th Mar 2017, 9:46 PM
Tashi N
Tashi N - avatar
+ 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; }
6th Mar 2017, 8:37 PM
Meharban Singh
Meharban Singh - avatar
0
thnx
6th Mar 2017, 8:44 PM
Kashish Gupta
Kashish Gupta - avatar