当前位置:网站首页>计算926的9260次方里的字符串里有多少个926
计算926的9260次方里的字符串里有多少个926
2022-06-11 19:28:00 【zhangsan3333】
package StringTest;
import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Math.pow;
public class String10 {
public static void main(String[] args) {
double a = pow(12, 2);
System.out.println("a = " + a);
//926的9260次方里的字符串里有多少个926
String sub = "926";
BigDecimal bigDecimal = new BigDecimal(926);
BigDecimal pow = bigDecimal.pow(9260);
String string = pow.toString();
System.out.println("string长度为 " + string.length());
int count1 = countSub1(string, sub);
System.out.println("count1 = " + count1);
System.out.println();
int count2 = countSub2(string, sub);
System.out.println("count2 = " + count2);
}
private static int countSub1(String string, String sub) {
int count = 0;
long begin = System.currentTimeMillis();
Matcher matcher = Pattern.compile(sub).matcher(string);
while (matcher.find()) {
count++;
}
long end = System.currentTimeMillis();
System.out.println("运行时间1 = " + (double) (end - begin) / 1000);
return count;
}
private static int countSub2(String string, String sub) {
int olcCount = string.length();
long begin = System.currentTimeMillis();
int newCount = string.replace(sub, "").length();
int count = (olcCount - newCount) / sub.length();
long end = System.currentTimeMillis();
System.out.println("运行时间2 = " + (double) (end - begin) / 1000);
return count;
}
}

边栏推荐
- Merge multiple binary search trees
- 激活函数公式、导数、图像笔记
- Experience of remote office communication under epidemic situation | community essay solicitation
- Introduction to go language (V) -- branch statement
- 【信号去噪】基于FFT和FIR实现信号去噪附matlab代码
- Web3游戏:游戏体验的探寻与重塑
- 【求助】请问如何让微信公众号文章在外部浏览器中打开后还能显示下方的精选留言?
- 2022各大厂最新总结的软件测试宝典,看完不怕拿不到offer
- RTL仲裁器设计
- Flutter--Button浅谈
猜你喜欢
![Leetcode: sword finger offer 59 - ii Maximum value of queue [deque + sortedlist]](/img/6b/f2e04cd1f3aaa9fe057c292301894a.png)
Leetcode: sword finger offer 59 - ii Maximum value of queue [deque + sortedlist]

给你一个项目,你将如何开展性能测试工作?

Raki's notes on reading paper: memory replace with data compression for continuous learning

懂机器学习如何入门量化交易?

图床:PicGo+腾讯云+typora

Record the phpstudy configuration php8.0 and php8.1 extension redis

关于富文本储存数据库格式转译问题

Performance of MOS transistor 25n120 of asemi in different application scenarios

Pyqt5 tips - button vertical display method, QT designer sets button vertical display.

Merge multiple binary search trees
随机推荐
Judge whether it is a balanced binary tree
What started mongodb? What are the application scenarios?
Introduction to ieda bottom menu
干货丨MapReduce的工作流程是怎样的?
图床:PicGo+腾讯云+typora
Image transformation torchvision Transforms notes
Qubicle notes: self set shortcut keys (attached with Lao Wang's self set shortcut key file)
【求助】请问如何让微信公众号文章在外部浏览器中打开后还能显示下方的精选留言?
Review of software testing technology
I don't want to open an account online. Is it safe to open an account online?
Practice of tag recognition based on Huawei cloud image
SISO decoder for repetition (supplementary Chapter 4)
Pyqt5 tips - button vertical display method, QT designer sets button vertical display.
[image denoising] image denoising based on Markov random field with matlab code
Anaconda安装、Jupyter Notebook默认启动路径修改及Nbextensions插件安装
AHB2APB_bridge 设计
Postman configuration Chinese
Introduction to go language (VI) -- loop statement
关于富文本储存数据库格式转译问题
Hospital intelligent infusion management system source code hospital source code