输入数字对应的英文组合,输出对应的数字组合

	/*
	 * 输入数字对应的英文组合,输出对应的数字组合
	 */
	private void test(){
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("zero", 0);
		map.put("one", 1);
		map.put("two", 2);
		map.put("three", 3);
		map.put("four", 4);
		map.put("five", 5);
		map.put("six", 6);
		map.put("seven", 7);
		map.put("eight", 8);
		map.put("nine", 9);
		System.out.print("输入:");
		Scanner sc = new Scanner(System.in);
		String in = sc.next();
		int temp=0;
		System.out.print("输出:");
		//遍历字符串
		for (int i = 1; i < in.length()+1; i++) {
			String s=in.substring(temp, i);
			if(map.get(s)!=null){
				System.out.print(map.get(s));
				temp=i;
			}
		}
	}

  

posted on 2017-02-24 16:39  leeliwen  阅读(304)  评论(0编辑  收藏  举报