package com.company; import java.util.*; public class Main { public static void main(String[] args) { System.out.println("请输入一段英文语句"); Scanner sc = new Scanner(System.in); String strPare = sc.nextLine(); Map<String,Integer> mapPara = new HashMap<String,Integer>(); String[] strArray = strPare.split(""); int iCount = 0; for(String str : strArray) { if(!mapPara.containsKey(strPare)) { mapPara.put(str,1); } else { iCount = mapPara.get(str); iCount++; mapPara.put(str,iCount); } } for(Map.Entry<String,Integer> me : mapPara.entrySet()) { String strKey = me.getKey(); Integer strValue = me.getValue(); System.out.println(strKey+"出现了"+strValue+"次"); } } }
1027学习记录
最新推荐文章于 2024-04-20 11:56:13 发布