1234567891011121314151617181920212223242526272829303132 |
- package com.loveCoding.homework.j20250517;
- /**
- * @author WanJl
- * @version 1.0
- * @title T9
- * @description **9. 数字频率统计**
- * 要求:统计数组中每个数字出现的次数(假设数字范围0-9)
- * 示例输入:`{2,5,3,2,8,2}`
- * 示例输出:
- * `2出现3次`
- * `3出现1次`
- * `5出现1次`
- * `8出现1次`
- * @create 2025/5/24
- */
- public class T9 {
- public static void main(String[] args) {
- int[] arr = {2, 5, 3, 2, 8, 2, 2};
- for (int i = 0; i < arr.length; i++) {
- int count = 0;
- for (int j = i; j < arr.length; j++) {
- if (arr[i] == arr[j]) {
- count++;
- }
- }
- System.out.println(arr[i] + "出现" + count + "次");
- }
- }
- }
|