import java.io.*;
class Factorial{
public static void main(String[] args) {
try{
BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the number");
int a= Integer.parseInt(object.readLine());
int fact= 1;
System.out.println("Factorial of " +a+ ":");
for (int i= 1; i<=a; i++){
fact=fact*i;
}
System.out.println(fact);
}
catch (Exception e){}
}
}
Trying numbers equal or greater than 17 outputs a negative number. Why?!?!
And not only that, but the answers are only correct up to 12. Inputting 13 or higher gets you wrong answers. Inputting 62 gives you 0. Is this due to the int boundaries?
I am pretty sure it is, but why do I get negative numbers O_O?