【Debug】

握草 握草 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package math011;

public class Math011 {
public static void main(String[] args) {
int maxCycleLength=0;
for(int i=2; i<=1000; ++i) {
double tmpDecimal=(double)1/i;
String tmpStr=String.valueOf(tmpDecimal).substring(0,500);
int tmpCycleLength=getMaxCycleLength(tmpStr);
if(tmpCycleLength>maxCycleLength) {
maxCycleLength=tmpCycleLength;
}
}
System.out.println(maxCycleLength);
}

public static int getMaxCycleLength(String str) {
int maxCycleLength = 0;
int tmpCycleLength = 0;
for (int i = 1; i < str.length(); ++i) {
for (int j = 0; j < str.length() - i; ++j) {
if (str.charAt(j) == str.charAt(i + j))
tmpCycleLength++;
// As follow, tmpCycle is always change, and pass the value to the maxCycle,
// finally the value will be fixed.
else
tmpCycleLength = 0;
if (tmpCycleLength > maxCycleLength) {
maxCycleLength = tmpCycleLength;

}

}
}
if (maxCycleLength > 0)
return maxCycleLength;
return -1;

}


}


如上,要求找出1/2, 1/3, 1/4。。。1/1000 之中的循环节最多的一个数
为什么这样写在主方法中会导致:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 500
at java.lang.String.substring(String.java:1963)
at math011.Math011.main(Math011.java:8)

这样的错误??
...全文

相关推荐

SAP ABAP DEBUG 方式总结

SAP ABAP DEBUG 方式总结 一、一般Debug 1、内、外部断点。外部断点功能涵盖了内部断点 2、图上方红框为一次为F5\F6\F7\F8 3、在Debug 进入内表时,可以通过右侧的工具按钮来对内表内容的增删改。 4、若DEBUG想返回上一步重新执行操作,可以通过鼠标右键选中想返回的行,点击“转到语句”进行操作。 5、Condition point 6、Watchpoint 7、Break point at message. 8、Hardcode: Breakpoint at program 8.1 Break 8.2 Break-Point 8.3 Log-Point 二、弹窗程序Debug 三、后台作业 Debug 四、报错程序的Debug 五、运行中程序Debug 六、Smartforms Debug 七、Debug 其他用户程序 八、Update 模式下的function debug Additional

SAP_太亿真仙

在Win64下运行debug(Debug+DOSbox)

在学习汇编语言时,debug不失为练习得好工具。读者操作系统若为32位,可直接运行debug。 在64位操作系统下,想运行debug,需要两个东西:DOSBox,debug.exe。 1,下载、安装DOSBox。 2,下载debug.exe,将debug.exe文件放置在磁盘,例如:D:debug\ 3,运行DOSBox.exe,输入:mount c D:debug\, Enter后,提示如下图 PS: 此处c为DOSBox安装磁盘,D:debug\为debug.exe文件位置 4,执行c:切换到自己得磁盘后,即可执行debug 配置dosbox.config文件,每次运行DOSBox可以不用输入以上命令: 打开dosbox.config,在最后一行添加: mount c D:\debug c: debug

gwzz1228

python开启debug模式的方法

主要介绍了python开启debug模式的方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

weixin_38724535

关于SAP Debug的基本知识

关于SAP Debug的基本知识 介绍了debug的基础知识 有一定的帮助

lovewell1004

DOSBox和debug文件

对于win10 不能够使用debug进行汇编语言的学习与设计,现在给出win10安装debug的解决方案的物理文件。

Ambition_Bit
评论 6
收藏 已收藏
分享
返回顶部
握草
Java SE 62,621 成员 307,251 内容