1
我正在尝试编写一个涉及函数的代码,该函数以字符串形式输入数字,并将该输入的其余部分以7除以int后返回。处理大数字时出现运行时错误
虽然代码适用于更小的数字,它处理大量的输入时,显示如下提示运行时错误..
Runtime error time: 0.04 memory: 711168 signal:-1
Exception in thread "main" java.lang.NumberFormatException: For input string: "5449495"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.math.BigInteger.<init>(BigInteger.java:470)
at java.math.BigInteger.<init>(BigInteger.java:597)
at Ideone.remainderWith7(Main.java:13)
at Ideone.main(Main.java:22)
我的代码如下..
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone {
int remainderWith7(String num) {
// Your code here
java.math.BigInteger bg = new java.math.BigInteger(num);
//System.out.println(num);
Integer n = bg.intValue();
return (int) n % 7;
}
public static void main(String[] args) throws java.lang.Exception {
// your code goes here
Ideone id = new Ideone();
System.out.println(id.remainderWith7("56495654565052555054535456545355495650575755555757575350505449495254525056535655494951545354515152515050575749545453535549545551575652535149494949515551545554565555575452555157505555574950505649525149505150575254515549565156515750555450545355495355515251495352565452555453515451505251575251494956515352555154505155535151565754505450535753555654575549575349565351575054"));
}
}
很适合您编辑和指定错误。我只瞥了一眼,发现在整个BigInteger强制下来之后你使用了模数。我现在已经发现了一部分问题。 – Makoto
(我自己在运行后实际添加了特定的错误) – qxz
@qxz:好的,谢谢你。 – Makoto