I made code which computes the factorial of the user inputted number, but anything past 12! I get the wrong number and anything past 16! I get negative numbers. What is the reason for this and is there a solution fix this?
import java.util.Scanner;
class Factorial {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Integer input = keyboard.nextInt();
int fact = 1;
for (int i = 1; i <= input; i++) {
fact = fact * i;
}
System.out.println(fact);
keyboard.close();
}
}