兰聪


私信TA

用户名:lc2024228712

访问量:2757

签 名:

等  级
排  名 143
经  验 7158
参赛次数 8
文章发表 18
年  龄 0
在职情况 学生
学  校 鄂州职业大学
专  业

  自我简介:

参考代码:

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 统计一个给定字符串中指定的字符出现的次数。
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String str1 = sc.nextLine();
			if(str1.equals("#")) {
				return;
			}
			String str2 = sc.nextLine();
			
			for (int i = 0; i < str1.length(); i++) {
				int count = 0;
				for (int j = 0; j < str2.length(); j++) {
					if(str1.charAt(i) == str2.charAt(j)) {
						count++;
					}
					
					if(j == str2.length()-1) {
						System.out.println(str1.charAt(i) + " " + count);
					}
					
				}
			}
			
		}

	}

}


 

0.0分

4 人评分

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

编程语言转换

万能编程问答

代码解释器

  评论区