您的位置:首页 > 编程语言 > Java开发

《Java实战开发经典》第五章5.3

2015-08-25 10:33 459 查看
package xiti5;
public class Third {
public static void main(String[] args) {
T t=new T("want you to know one thing ");
t.tell();
}

}
class T{
private String str;
public T(String str){
this.str=str;
}

public void tell(){
char c[]=str.toCharArray();//将字符串分解为字符数组
int n=0;
int m=0;
for(int i=0;i<c.length;i++){
if(c[i]=='n'){
n++;
}else
if(c[i]=='o'){
m++;
}
}
System.out.println("该字符串中n出现了"+n+"次,o出现了"+m+"次");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java