원래 자바에는 아주 큰 정수를 계산하는 Big Integer라는 것이 있지만, 나는 그냥 기존의 변수형으로 해결하기로 했다.
그리고 어떻게 할지 생각하던중... 스치는 생각이 바로!
사람들이 계산하는 방법으로 계산하자!
package math;
public class bigNums {
public static void main(String[] args) {
// TODO Auto-generated method stub
bigNums bn = new bigNums();
bn.calculate();
}
public void calculate() {
int save = 0;
int cal = 0;
String print = "";
String str = "1";
for (int j = 1; j < 101; j++) {
for (int i = str.length(); i > 0; --i) {
save = (j * Integer.parseInt(str.substring(i - 1,i)));
save += cal;
if (save > 9) {
cal = (save / 10);
save = (i == 1)? save : (save % 10);
} else {
cal = 0;
}
print = Integer.toString(save) + print;
}
str = print;
cal = 0;
System.out.println(print);
print = "";
}
}
}
이다. 한번 실행해보고 안돼는 것은 댓글로...
'JAVA' 카테고리의 다른 글
[자바] 소수를 구하는 프로그램 만들기 (0) | 2018.11.13 |
---|---|
자바 외전, 삼항연산자 (0) | 2018.04.11 |
자바 세번째-반복문 (0) | 2018.04.08 |
엘리베이터 프로그램 (0) | 2018.03.30 |
자브아 두번째, 변수 (0) | 2018.03.25 |