Java不用集合实现统计字符串里每个字符出现次数

/**
 * @author Ancient Jazz
 * @create 2019-05-28 19:30
 **/
public class String_Count_Array {
    public static void main(String[] args) {
        String str = new Scanner(System.in).nextLine();
        char[] chars = str.toCharArray();
        int count=0;
        //数组去重,用于结果输出
        Object[] objects = ifRepeat(chars);
        for (char c : chars) {
            for (Object object : objects) {
                count=count(chars, (Character) object);
                System.out.println(object+"输出"+count+"次");
            }
            break;
        }
    }

    private static int count(char[] chars, char c) {
        int count=0;
        for (char b : chars) {
            if (c==b){
                count++;
            }
        }
        return count;
    }

    //去重方法借鉴作者:花和尚也有春天
    //来源:CSDN
    //原文:https://blog.csdn.net/weixin_38750084/article/details/84196256
    //版权声明:本文为博主原创文章,转载请附上博文链接!
    private static Object[] ifRepeat(char[] arr){
        //用来记录去除重复之后的数组长度和给临时数组作为下标索引
        int t = 0;
        //临时数组
        Object[] tempArr = new Object[arr.length];
        //遍历原数组
        for(int i = 0; i < arr.length; i++){
            //声明一个标记,并每次重置
            boolean isTrue = true;
            //内层循环将原数组的元素逐个对比
            for(int j=i+1;j

你可能感兴趣的:(Java不用集合实现统计字符串里每个字符出现次数)