题目:
代码:
import java.util.Scanner;
public class LargestNumber {
public static void main(String[] args) {
int n;
int[] values;
int[] count;
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
values = new int[n+1];
count = new int[n+1];
for(int t=1;t<=n;t++)
count[t] = 0;
for(int k=1;k<=n;k++)
values[k] = scan.nextInt();
for(int i=1;i<=n-1;i++) {
if(count[i] == Integer.MIN_VALUE)
continue;
for(int j=i+1;j<=n;j++) {
if(values[i]==values[j]) {
count[i]++;
count[j] = Integer.MIN_VALUE;
}
}
}
int temp = 1;
for(int s=1;s<=n;s++) {
if(count[s]>count[temp]) {
temp = s;
}
if(count[s]==count[temp]) {
if(values[s]<values[temp])
temp = s;
}
}
System.out.println(values[temp]);
}
}
主类名称改为Main
1)注意审题,要求两个次数相同,输出数值较小的数
2)学会自己设置输入样例进行测试