java - generating int up to 100 million throws exception -
i trying generate integers 100 million, combine pre-defined integer/string.
example: predefined = 1010 generated: gen = 5020315 combined = 10105020315
then save number .txt file, text file should have 100 1000000 lines.
here code wrote:
import java.io.filenotfoundexception; import java.io.printwriter; import java.io.unsupportedencodingexception; public class exec{ public static void main(string[] args) throws filenotfoundexception, unsupportedencodingexception { int initial = 6618; printwriter author = new printwriter("variations.txt", "utf-8"); for(int = 0; < 100000000; a++){ int a2 = integer.parseint(integer.tostring(initial) + integer.tostring(a)); writer.println(a2); } writer.close(); } }
but throws next error:
exception in thread "main" java.lang.numberformatexception: input string: "6618100000"
why happen? problem?
you need long , , can utilize long.parselong();
. largest value int long 2^31-1 long 2^63-1.
java
No comments:
Post a Comment