Java统计字符串中字符出现次数的方法示例
作者:xxiaowen 时间:2023-11-25 08:23:02
本文实例讲述了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);
}
}
运行结果:
希望本文所述对大家java程序设计有所帮助。
来源:http://blog.csdn.net/wenzhilanyu2012/article/details/12921913
标签:Java,统计,字符串
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Gradle修改本地仓库的位置方法实现
2022-01-17 21:25:52
![](https://img.aspxhome.com/file/2023/0/62720_0s.png)
SpringBoot整合MybatisPlus实现增删改查功能
2022-10-31 05:24:15
![](https://img.aspxhome.com/file/2023/8/65728_0s.png)
Java利用POI读取、写入Excel的方法指南
2023-11-23 15:39:23
![](https://img.aspxhome.com/file/2023/9/59899_0s.png)
java:程序包org.springframework.boot不存在的完美解决方法
2023-09-03 20:37:32
![](https://img.aspxhome.com/file/2023/3/84163_0s.jpg)
关于spring boot中几种注入方法的一些个人看法
2022-09-07 10:15:14
Spring Boot 实现图片上传并回显功能
2021-10-11 17:45:20
![](https://img.aspxhome.com/file/2023/6/68776_0s.png)
解析c#操作excel后关闭excel.exe的方法
2021-08-14 16:55:22
Java锁擦除与锁粗化概念和使用详解
2022-02-09 15:32:30
android指定DatePickerDialog样式并不显示年的实现代码
2022-07-13 05:23:08
![](https://img.aspxhome.com/file/2023/4/91684_0s.jpg)
Jetpack Compose修饰符专项精讲
2021-11-28 06:33:21
![](https://img.aspxhome.com/file/2023/4/103884_0s.png)
使用Spring Data Redis实现数据缓存的方法
2021-08-02 10:19:25
![](https://img.aspxhome.com/file/2023/6/71706_0s.png)
java线程组构造方法源码解析
2022-11-24 08:58:26
![](https://img.aspxhome.com/file/2023/3/80273_0s.jpg)
Java 三种进制的数值常量操作
2021-11-14 21:39:41
Java中i++的一些问题总结
2022-04-11 18:07:34
Android 高版本API方法在低版本系统上的兼容性处理
2022-08-22 08:51:53
C# TSC打印二维码和条形码的实现方法
2021-10-06 14:39:53
![](https://img.aspxhome.com/file/2023/5/110185_0s.png)
c# 引用Nlog插件的步骤
2021-08-10 01:03:43
![](https://img.aspxhome.com/file/2023/7/111257_0s.png)
java开发MVC三层架构上再加一层Manager层原理详解
2023-06-14 06:10:51
![](https://img.aspxhome.com/file/2023/1/60371_0s.jpg)
实战android打包和签名
2023-11-18 10:23:50
![](https://img.aspxhome.com/file/2023/4/138854_0s.png)
java异步编程之一文看完其异步函数表
2021-12-25 10:57:39