`
^佐依^
  • 浏览: 17398 次
  • 性别: Icon_minigender_2
  • 来自: 惠安
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Toy Program 3

阅读更多
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架构的论坛 只是一个toy program 适合大学做课程设计

    这是我期末做的课程设计 是基于ssh + mssqlver的 只是一个小程序 有需要的同学可以下载 呵呵 应付老师足够了

    Introduction to 64Bit Windows Assembly

    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 ...

    Learn Electronics with Arduino

    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 ...

    Mathematica programming: an advanced introduction

    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 ...

    professional_windows_embedded_compact_7.pdf

    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 ...

    nodejs in action 英文

    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 ...

    [黑莓游戏开发学习][Learn BlackBerry Games Development]

    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 2nd Robert Sedgewick

    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, 2nd Edition (2017.4出版.EPUB格式)

    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 ...

    Vulcain:面向Vulkan的图形的玩具项目

    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...

    智能循迹避障小车设计毕业设计.docx

    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 &lt;= 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 ...

Global site tag (gtag.js) - Google Analytics