I tested it with negative number, 0, and positive number less than 150, it worked fine.

package com.codegym.task.task15.task1531;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
/*
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();
if (input<151)
System.out.println(factorial(input));
}
public static String factorial(int n) {
//write your code here
int r=0;
if (n==0||n==1||n<0) r=1;
if (n>1) r=Integer.parseInt(factorial(n-1))*n;
return Integer.toString(r);
}
}