【测开面试题-003】统计一个字符串中各个数字出现次数
package com.course.coke; public class Que2 { public static void main(String[] args) { String s = "123004533"; char[] array = s.toCharArray(); int[] count = new int[10]; // 存放个数 for (int i = 48; i < 58; i++) { int a = 0; for (int j = 0; j < array.length; j++) { if (array[j] == i){ a++; } } count[i-48] = a; } for (int i = 0; i < count.length; i++) { System.out.println(i + "的个数是:"+count[i]); } } }
---------------------------------------------------
立足软件测试领域,并重新定义测试!
---------------------------------------------------