Hi guys,
I've been stuck for hours.
I've used the help section and google but it won't pass.
my output adds a bunch of 0s for the higher numbers.
package com.codegym.task.task15.task1531;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
/*
Factorial
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
reader.close();
System.out.println(factorial(input));
}
public static String factorial(int n) {
//write your code here
if(n < 0) {
return "0";
} else if(n == 0) {
return "0! = 1";
} else {
BigInteger fact = new BigInteger("1");
for (int i = 1; i <= n; i++) {
fact = fact.multiply(new BigInteger(n +""));
}
return fact.toString();
}
}
}