曾刚炜


私信TA

用户名:13397282061

访问量:3647

签 名:

等  级
排  名 168
经  验 6784
参赛次数 0
文章发表 19
年  龄 20
在职情况 学生
学  校 湖北生物科技职业学院
专  业

  自我简介:

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

public class Main1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] strs = str.split("\\W+");
		Map<String, Integer> map = new LinkedHashMap<String, Integer>();
		for (String s : strs) {
			String c=s.toUpperCase();
			if (map.containsKey(c)) {
				map.put(c, (map.get(c) + 1));
			} else {
				map.put(c, 1);
			}
		}
		int max = 0;
		for (String c : map.keySet()) {
			if (c.length() > max) {
				max = c.length();
			}
		}
		for (String c : map.keySet()) {
			for (int i = 0; i < max - c.length(); i++) {
				System.out.print(" ");
			}
			System.out.print(c.toUpperCase() + ":");
			for (int i = 0; i < map.get(c); i++) {
				System.out.print("*");
			}
			System.out.println(map.get(c));
		}
	}
}
 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区