public class Count{
public static void main(String args[]){
int j=0,k=0;
char x='n';
char y='o';
String s="want you to know one thing";
char a[]=s.toCharArray();
for(int i=0;i<a.length;i++){
if(x==a[i]){
j++;
}
if(y==a[i]){
k++;
}
}
System.out.println("字母n出现的次数:"+j+"次 "+"字母o出现的次数:"+k+"次");
}
}
Java 编写程序,统计字符串“want you to know one thing”中字母n和字母o的出现次数
最新推荐文章于 2022-08-04 22:30:03 发布