我在poj上面做题题号1001老是出现runtime error,测试题目给的用例却是对的

qq_38423382 2019-09-07 05:18:11
第一次做oj的题目



代码





import java.util.Scanner;

public class work1001 {
public static String R;
public static int n;
public static int[] result;
public static int[] jieguo;
public static int point_index;
public static int[] chengshu;
public static void main(String[] arg){
result=new int[150];
jieguo=new int[150];
chengshu=new int[5];
Scanner input =new Scanner(System.in);
while (true){
R=input.next();
n=input.nextInt();
System.out.println("");
point_index=0;
for (int i=0;i<150;i++){
result[i]=0;
jieguo[i]=0;
}
for (int i=R.length()-1,j=0;i>=0;i--){
if(R.charAt(i)=='.'){
point_index=R.length()-1-i;
}else{
chengshu[j]=R.charAt(i)-'0';
result[j]=chengshu[j];
j++;
}
}
for (int i=2;i<=n;i++){
for (int j=0;j<5;j++){
if (chengshu[j]==0)
continue;
else
for (int k=0;k<140;k++){
jieguo[j+k]+=chengshu[j]*result[k];
}
}
for (int k=0;k<149;k++){
jieguo[k+1]+=jieguo[k]/10;
jieguo[k]=jieguo[k]%10;
}
for (int k=0;k<150;k++)
{
result[k]=jieguo[k];
jieguo[k]=0;
}
}
point_index=point_index*n;
int first=0;
for (int i=149;i>=0;i--){
if(result[i]==0){
continue;
}else
{
first=i;
break;
}
}
while (true){
if (first<point_index)
break;
System.out.print(result[first]);
first--;
}
if (first>0){
int last=point_index;
System.out.print('.');
for (int i=0;i<point_index;i++){
if(result[i]==0){
continue;
}else
{
last=i;
break;
}
}
while (true){
--point_index;
if (point_index<last)
break;
System.out.print(result[point_index]);
}
}
}
}
}
...全文
209 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_39936465 2019-09-09
  • 打赏
  • 举报
回复
引用 4 楼 qq_38423382 的回复:
我是改了的,之前没改成Main的时候是编译错误
runtime error 一般都是变量或数组的取值范围超限,把程序考到eclipse中看看报错按一行就知道了。
最小动能! 2019-09-09
  • 打赏
  • 举报
回复
检测你做的对不对用的不只是题目给的测试用例哦 所以你写的代码要有泛用性 ;用测试用例测试正确但是机器检查的时候错误是很正常的
wowpH 2019-09-07
  • 打赏
  • 举报
回复
引用 4 楼 qq_38423382 的回复:
我是改了的,之前没改成Main的时候是编译错误

最外层死循环了。
qq_38423382 2019-09-07
  • 打赏
  • 举报
回复
引用 2 楼 wowpH 的回复:
大多数 OJ 的 public 类必须是 Main。你将 work1001 改成 Main 试试。
我是改了的,之前没改成Main的时候是编译错误
wowpH 2019-09-07
  • 打赏
  • 举报
回复
注意是否出现死循环。
wowpH 2019-09-07
  • 打赏
  • 举报
回复
大多数 OJ 的 public 类必须是 Main。你将 work1001 改成 Main 试试。
qq_38423382 2019-09-07
  • 打赏
  • 举报
回复
萌新求助啊,太菜了

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧