最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Java统计字符串中字符出现次数的方法示例
时间:2022-06-29 02:33:28 编辑:袖梨 来源:一聚教程网
本文实例讲述了Java统计字符串中字符出现次数的方法。分享给大家供大家参考,具体如下:
package com.wenzhi;
import java.util.Scanner;
public class Test01 {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("请你输入字符");
String str = scan.nextLine();
Scanner scan1 = new Scanner(System.in);
System.out.println("请输入你要查找的子字符串");
String str1 = scan1.nextLine();
int count = 0;
int start = 0;
while (str.indexOf(str1, start) >= 0 && start < str.length()) {
count++;
start = str.indexOf(str1, start) + str1.length();
}
System.out.println(str1 + "在" + str + "出现的次数为" + count);
}
}
运行结果:
相关文章
- 墨守孤城女巫侠客流玩法搭配攻略 11-17
- 心动小镇沸雪浴场5个虫类攻略 11-17
- 不朽箴言孟婆无限自爆流玩法攻略 11-17
- 墨守孤城毒焰缠墨流玩法搭配攻略 11-17
- 新三国志曹操传沙盘1159层攻略 11-17
- 永远的蔚蓝星球星魄获取途径分享 11-17
