/**
*
* 类 描 述:机试题: 给定一个 hashMap 最终输出最大值的键
* 作 者: 赵 鹏
* 时 间:2017年7月4日 下午6:51:06
*/ public class Test { public static void main(String[] args) { Map<Integer, Integer> hashMap = new HashMap<Integer , Integer>(); //给定一个hashmap
hashMap.put(1, 45);
hashMap.put(2, 6666);
hashMap.put(3, 15);
hashMap.put(4, 100);
hashMap.put(5, 3210); //输出最大值的键
System.out.println(getMaxKey(hashMap)); } public static String getMaxKey(Map<Integer , Integer> hashMap) { int key = 0;
int value = 0; int flagKey = 0;
int flagValue = 0; Set<Entry<Integer,Integer>> entrySet = hashMap.entrySet(); for (Entry<Integer, Integer> entry : entrySet) { //key value 代表每轮遍历出来的值
key = entry.getKey();
value = entry.getValue(); if(flagValue < value ) { //flagKey flagValue 当判断出最大值是将最大值赋予该变量
flagKey = key;
flagValue = value; } } return String.valueOf(flagKey);
} }

最新文章

  1. C/C++头文件使用 #ifndef #define #endif 的原因
  2. 从Bayesian角度浅析Batch Normalization
  3. liunx 多个tomcat 产生的新问题
  4. 《DSP using MATLAB》示例Example4.11
  5. [工作中的设计模式]适配器模式adapter
  6. HTML5标签及使用方法描述
  7. 得到指定进程PID
  8. mahout入门指南之基于mahout的itembased算法
  9. HDU-2058-The sum problem(数学题技巧型)
  10. django-个人博客登录及权限验证功能的实现
  11. Java collection 容器
  12. nginx与PHP配置
  13. 依赖注入容器之Castle Windsor
  14. apt 下载安装包
  15. hibernate5(12)注解映射[4]一对一外键关联
  16. Unicode编码:保存中文cookie
  17. 切换svn登录账户
  18. Error creating bean with name &#39;sessionFactory&#39; defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable t
  19. 天梯赛 L2-024. (并查集) 部落
  20. Linux下文件的打包、解压缩指令——tar,gzip,bzip2,unzip,rar

热门文章

  1. 关于使用spring mvc前后端上传数据日期格式
  2. Ubuntu系统多屏幕时 触摸屏如何分屏定位
  3. C语言程序设计II—第四周教学
  4. MySQL(三)用正则表达式搜索
  5. co模块源码学习笔记
  6. 【原创】MVC +WebUploader 实现分片上传大文件
  7. 转 edtools
  8. C# 简单的 Job 作业~
  9. Awesome Python,Python的框架集合
  10. 快速零配置迁移 API 适配 iOS 对 IPv6 以及 HTTPS 的要求