최대 100,000,000 정수를 생성하려면 다음 정수/문자열을 미리 정의 된 결합하려고합니다.최대 1 억 번 int 예외 발생
Example: predefined = 1010 Generated: gen = 5020315 Combined = 10105020315
그런 다음 해당 번호를 .txt 파일에 저장하십시오. 따라서 텍스트 파일에는 1 억 줄이 있어야합니다. 여기
내가 쓴 코드 :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 writer = new PrintWriter("variations.txt", "UTF-8");
for(int a = 0; a < 100000000; a++){
int a2 = Integer.parseInt(Integer.toString(initial) + Integer.toString(a));
writer.println(a2);
}
writer.close();
}
}
그러나 다음과 같은 오류가 발생합니다 :
왜 이런 일이 않습니다를? 문제가 어디에 있습니까?Exception in thread "main" java.lang.NumberFormatException: For input string: "6618100000"
예외는 어디에서 받습니까? – msrd0
전체 스택 트레이스를 게시하십시오. int의 32 비트는 2147483648까지만 유효합니다.'long'이 필요합니다. – 9000
구성된 숫자를 가져 와서 다시 정수로 변환하는 목적은 무엇입니까? 문제없이 문자열로 출력 할 수 있습니다. – Compass