读入一个数字字符串,请统计其中 0~9 的各个数字的个数。

  • Post author:
  • Post category:其他


读入一个数字字符串,请统计其中 0~9 的各个数字的个数。

package sy.three;

public class Statistics {
   public static void main(String[] args){
      String a = "01232897435168712";
      System.out.println("输入的字符串为:"+a+"其中:");
      for(int i=0;i<=9;i++){
         int c = 0;
         for(int j=0;j<a.length();j++){
            String b = a.substring(j,j+1);
            if((""+i).equals(b)){
               c++;
            }
         }
         System.out.println("数字"+i+"出现的次数为:"+c+"次");
      }


   }
}



版权声明:本文为Tonyhnv原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。