参考代码:
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 人评分
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:504 |
杨辉三角 (C语言代码)浏览:484 |
判定字符位置 (C语言代码)浏览:792 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:662 |
找出最长的字符串来 (C语言代码)浏览:1762 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:485 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:500 |
简单的a+b (C语言代码)浏览:448 |
简单的a+b (C语言代码)浏览:244 |
计算表达式浏览:642 |