统计数字java代码,用数组做

统计一个数字中出现最多的数字,如果数字个数一样,则已最大的数字为准
用数组怎么做啊,刚学的数组😂

你是没思路还是什么?

有什么疑问,可以拿出来讨论

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = new int[10];
        char[] cs = sc.toCharArray();
        for(char c:cs){
            num[c-'0']++;
        }
        int max = 9;
        for(int i = 9;i >= 0;i--){
            max = num[i] > num[max]?i:max;
        }
        System.out.println(max);
    }