解题思路:
注意事项:
参考代码:
import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int ns[]=new int[n]; int max=0,index=0; ArrayList<Integer>list=new ArrayList<Integer>(); for (int i = 0; i < n; i++) { ns[i]=sc.nextInt(); list.add(ns[i]); } //去除list中重复项 list=new ArrayList<Integer>(new HashSet<Integer>(list)); for (int i = 0; i < list.size(); i++) { int sum=0; for (int j = 0; j < ns.length; j++) { if (list.get(i)==ns[j]) { sum++; } } if (sum>max) { max=sum; index=i; } } System.out.println(list.get(index)); } }
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:542 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:667 |
C语言训练-数字母 (C语言代码)浏览:608 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:541 |
核桃的数量 (C语言代码)浏览:872 |
蛇行矩阵 (C语言代码)浏览:507 |
IP判断 (C语言代码)浏览:539 |
数组输出 (C语言代码)浏览:703 |
生日日数 (C语言代码)浏览:1502 |
神奇的fans (C语言代码)浏览:987 |