当前位置:网站首页>Calculate the number of 926 in the string to the power of 9260 of 926
Calculate the number of 926 in the string to the power of 9260 of 926
2022-06-11 19:37: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 Of 9260 How many strings are there in the power 926
String sub = "926";
BigDecimal bigDecimal = new BigDecimal(926);
BigDecimal pow = bigDecimal.pow(9260);
String string = pow.toString();
System.out.println("string The length is " + 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(" The elapsed time 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(" The elapsed time 2 = " + (double) (end - begin) / 1000);
return count;
}
}

边栏推荐
- In 2021, the global barite product revenue was about $571.3 million, and it is expected to reach $710.2 million in 2028
- Image transformation torchvision Transforms notes
- 01. Telecommunications_ Field business experience
- vs2010链接sql2008数据库时无法打开
- [assembly] analysis of Experiment 7 of the fourth edition of assembly language
- YOLOv3 Pytorch代码及原理分析(一):跑通代码
- PIL pilot image processing [1] - installation and creation
- Questions and requirements of marketing course design in autumn 21 of Dagong [standard answer]
- Introduction to go language (VI) -- loop statement
- Pyramid test principle: 8 tips for writing unit tests
猜你喜欢

Operator new and placement new

Pyramid test principle: 8 tips for writing unit tests
【求助】请问如何让微信公众号文章在外部浏览器中打开后还能显示下方的精选留言?

激活函数公式、导数、图像笔记

程序员10年巨变,一切都变了又好像没变...

司空见惯 - 会议室名称
![[assembly] analysis of Experiment 7 of the fourth edition of assembly language](/img/ac/a3c5bfeb2dcb93b123dd337993bab3.jpg)
[assembly] analysis of Experiment 7 of the fourth edition of assembly language

RTL仲裁器设计

5g communication test manual based on Ti am5728 + artix-7 FPGA development board (dsp+arm)

556. 下一个更大元素 III-(31. 下一个排列)-两次遍历
随机推荐
干货丨MapReduce的工作流程是怎样的?
Chrome tips - browser web page setting coding, solving the problem of web page garbled code, obtaining the latest version of charset plug-in, UTF-8 coding setting
Specific methods for porting WinCC flexible 2008 project to botu WinCC
[Multisim Simulation] generate square wave and triangular wave generators by operational amplifier
CMU 15-445 数据库课程第五课文字版 - 缓冲池
Raki's notes on reading paper: memory replace with data compression for continuous learning
Common - name of conference room
Understand how to get started with machine learning to quantify transactions?
程序员10年巨变,一切都变了又好像没变...
[signal denoising] speech adaptive denoising based on nonlinear filter with matlab code
2022各大厂最新总结的软件测试宝典,看完不怕拿不到offer
Review of software testing technology
Image transformation torchvision Transforms notes
Golang学习笔记—基础篇
[untitled]
cocan yocto buildroot
Programmers have changed dramatically in 10 years. Everything has changed, but it seems that nothing has changed
RTL仲裁器设计
Building web applications
MySQL——事务