人生的第一道编程笔试题

本题以激励自己继续向前,菜到抠脚,好好学习!

继续学习算法,继续刷题!

!!!!!!!!!!!!!!!!

2019-04-09

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 给定一个整数数组A,拥有N个不重复的整数,找到数组中两数之和出现最多的数
 * 如果有多种可能,输出全部结果,结果无序任意
 * @author Duanxi Cao
 *
 */
public class Test9 {
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int arr[] = new int[N];
		for(int i=0; i map = new HashMap<>();
		for(int i=0; i value = map.values();
		int maxCount = Collections.max(value);
		for(Map.Entry m :map.entrySet()) {
			if(m.getValue() >= maxCount) {
				System.out.println(m.getKey());
			}
		}
		s.close();
	}
}

验证的数为

8

1 8 3 11 4 9 2 7

输出结果:

10

11

12

你可能感兴趣的:(自我记录,学习)