Я понимаю, что при больших числах выводит не правильный результат Я так понимаю long не хватает Так что делать не знаю?
package com.javarush.task.task15.task1531;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
/*
Факториал
*/
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) {
if (n < 0) {
return "0";
}
else {
long x = n;
String f = Long.toString(factorial2(x));
return f;
}
}
public static long factorial2 (long b){
if (b <= 1) {
return 1;
} else {
return b * factorial2(b - 1);
}
}
//add your code here
}