Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.math.BigInteger;
- import java.util.Scanner;
- public class FactorsOfFactorial {
- public static void main(String[] args)
- {
- while(true)
- {
- BigInteger n = BigInteger.valueOf(new Scanner(System.in).nextInt());
- factorial(n);
- }
- }
- public static BigInteger recursiveFactorial(BigInteger n)
- {
- if(n.equals(BigInteger.ONE))
- return BigInteger.ONE;
- return n.multiply(recursiveFactorial(n.subtract(BigInteger.ONE)));
- }
- public static void factorial(BigInteger n)
- {
- BigInteger val = BigInteger.ONE;
- for(BigInteger i = n; i.compareTo(BigInteger.ONE) == 1; i = i.subtract(BigInteger.ONE))
- {
- val = val.multiply(i);
- System.out.println("i: " + i);
- }
- File f = new File("fact1.out");
- try {
- f.createNewFile();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- FileWriter scan;
- try {
- scan = new FileWriter(f);
- scan.write(val.toString());
- scan.close();
- System.out.println("Printed");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement