-
lzjccc
int i=0;
int j=0;
String str="want you to know one thing";
for(i=0;i<str.length();i++){
if(str.charAt(i)=='n'){
j++;
}
}
System.out.print(j);
-
badbomb
String str = "want you know one thing";
int num=0;
for(int i=0; i<str.length(); i++){
if(str.charAt(i) == 'n'){
num++;
}
}
System.out.println(num);
-
萨达哈鲁
。。。哥们。。。作业的话自己做一做领悟得更深一些吧。。直接要代码对自己的学习一点也不好。。。你可以多问问细节。。
-
adn_boy
String str = "want you to know one thing";
int n = 'n';
char [] chars = str.toCharArray();
int count = 0;
for (int i = 0;i < chars.length;i++){
if((int)chars[i] == n){
count ++;
}
}
-
损失函数
亲测可用String ss = "want you to know one thing"; byte[] ssb= ss.getBytes(); byte[] s = "n".getBytes(); int i = 0; for (byte b : ssb) { if(b == s[0]){ i++; } } System.out.println(i);
-
六道骸
String s= "want you to know one thing";String[] ssss = s.split("n");ssss 的长度-1;