5-3 编写程序

来源:互联网 发布:nginx https 二级域名 编辑:程序博客网 时间:2024/06/03 22:10

5-3 编写程序,统计出字符串“want you to know one thing”中字母n和字母o的出现次数。

class Number{    private  int x=0;    private static int y=0;    private char c[];    public Number(String str){        this.c=str.toCharArray();           }    public void search(){        for(int i=0;i<c.length;i++){            if(c[i]=='a') {x++;}            if(c[i]=='o') {y++;}        }        System.out.println("共有字母"+'a'+"\t"+x+"个");        System.out.println("共有字母"+'o'+"\t"+y+"个");    }}public class fiveDemo03{    public static void main(String args[]){        String want="want you to know one thing";        Number num=null;        num=new Number(want);        num.search();    }}
0 0
原创粉丝点击