import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
//有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数。
public class Play2{
public static void main(String[] args) {
String str="中国aadf的111萨bbb菲的zz萨菲";
Map<Character,Integer> m=new HashMap<Character,Integer>();
for(int i=0;i<str.length();i++){
Character c=str.charAt(i);
Integer n=m.get(c);
m.put(c, n==null?1:n+1);
}
//第一种遍历Map的方法
for(Map.Entry<Character, Integer> me:m.entrySet()){
System.out.println(me.getKey()+":"+me.getValue());
}
//第二种遍历Map的方法
Set<Character> s=m.keySet();
Iterator<Character> iter=s.iterator();
while(iter.hasNext()){
char key=iter.next();
System.out.println(key+":"+m.get(key));
}
//第三种遍历Map的方法
for(Character key:m.keySet()){
System.out.println(key+":"+m.get(key));
}
}
}
面试题,比较简单。
分享到:
相关推荐
这是我期末做的课程设计 是基于ssh + mssqlver的 只是一个小程序 有需要的同学可以下载 呵呵 应付老师足够了
The Toy Box allows the use to enter variable definitions and expressions in either C++ or Fortran and it builds a program to evaluate the expressions. Then the user can inspect the format of each ...
Do you have an idea for a new proof-of-concept tech device or electronic toy but have no way of testing the feasibility of the device? Have you accumulated a junk box of electronic parts and are now ...
program design and development, simulations etc are used. Mathematica seems to be an ideal tool for development of toy - models, prototypes, or just ideas. While Mathematica may be also quite useful ...
Learn to program an array of customized devices and solutions As a compact, highly efficient, scalable operating system, Windows Embedded Compact 7 (WEC7) is one of the best options for developing a ...
Around the "Ajax revolution" in 2005, JavaScript went from being a "toy" language to something people write real and significant programs with. Some of the notable firsts were Google Maps and Gmail ...
How to program games for any BlackBerry device, from the earliest Java-enabled smartphones to models that run the latest BlackBerry 5 operating system How to build games for two players or the whole ...
Introduction to Programming in Java, Second Edition, by Robert Sedgewick and Kevin Wayne is an accessible, interdisciplinary treatment that emphasizes important and engaging applications, not toy ...
Introduction to Programming in Java, Second Edition, by Robert Sedgewick and Kevin Wayne is an accessible, interdisciplinary treatment that emphasizes important and engaging applications, not toy ...
Toy project for Vulkan oriented graphics Copyright (C) 2021 Guillaume Vara This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as...
Car is running the program, under the existing toy electric car, based on the installation of super sonic sensor and infrared sensors, to achieve the location of electric vehicles,operational status ...
fn double [n] () { (n * 2 )}( 9 ) .double .println .-- output: 18 -- Um programa que conta até dez( 0 ) . set i .while i <= 10 { (i) . println . (i + 1 ) . set i .} -- Calcula o fatorial de um n...
RS482-M 03/16/2006 FOR Tongfang 清华同方电脑公司选用的BIOS芯片代号为RS482-M 日期为2006年3月16号 Main Processor : AMD Athlon™64 x2 dual core Processor 3600+ CPU为AMD3600+ 速龙64位双核酷睿技术 Memory ...