fatorial com biginteger
unknown
plain_text
2 years ago
685 B
5
Indexable
Never
import java.math.BigInteger; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) { System.out.println(fac(0)); System.out.println(fac(1)); System.out.println(fac(2)); System.out.println(fac(3)); System.out.println(fac(5)); System.out.println(fac(22)); } public static String fac(int n) { Map<Integer, BigInteger> map = new HashMap<>(); BigInteger atual = BigInteger.ONE; for (int i = 1; i <= n; i++) { atual = atual.multiply(BigInteger.valueOf(i)); map.put(i, atual); } return atual.toString(); } }