点击(此处)折叠或打开
import java.io.*; import java.util.*; public class cmd { public static void main(String args[]) { String str[] = {"a","b","a","b","c","a","b","c","b"}; HashMap hm = new HashMap(); int count1 = 0,count2 = 0,count3 = 0; for (int i = 0;i < str.length;i++) { if (str[i].equals("a")) { count1++; } else if (str[i].equals("b")) { count2++; } else if (str[i].equals("c")) { count3++; } else{} } hm.put("a",count1); hm.put("b",count2); hm.put("c",count3); System.out.println(hm); } } 运行结果如下: {b=4, c=2, a=3} <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 阅读(105) | 评论(0) | 转发(0) | 0上一篇:疯狂java讲义习题7.2
下一篇:疯狂java讲义习题7.4
相关热门文章 Tomcat 6 配置SSI让Resin支持shtml(SSI)- 静...tomcat + ssiASP JavaScript Lessons(8-14)JDK1.6官方下载_JDK6官方下载_... 给主人留下些什么吧!~~ 评论热议