+ 1
What do y'all think about it? Can you do better? Method to count the number of xs in a string (can work with any other strings)
int countXX(String str) { if(str.length()<=0)return 0; char[]count=str.toCharArray(); int index=0; for(int i=0;i<count.length;i++) { if(count[i]=='x') { index++;} } if(index==0)return 0; return index; }
2 Respostas
+ 2
Could be simplified to:
int countXX(String str) {
int index=0;
for(int i=0;i<str.length();i++)
if(str.charAt(i)=='x')
index++;
return index;
}
+ 2
John Wells cool thanks a lot !