编写程序,统计出字符串“want you to know one thing”中字母N和字母O的出现次数

编写程序,统计出字符串“want you to know one thing”中字母N和字母O的出现次数
编写程序,统计出字符串“want you to know one thing”中字母N和字母O的出现次数

//编写程序,统计出字符串“want you to know one thing”中字母N和字母O的出现次数class Count

{

private static int numN=0;

private static int numO=0;

private char c[];

public Count(String info)

{

this.c=info.toCharArray();

}

public void print()

{

for (int i=0;i

{

if (c[i]=='n')

{

numN++;

}

if (c[i]=='o')

{

numO++;

}

}

System.out.println("有N的个数为:"+numN+"\n"+"有O的个数为:"+numO);

}

}

public class Test03

{

public static void main(String args[])

{

Count cou=new Count("want you to know one thing");

cou.print();

}

}

相关主题
相关文档
最新文档