Factorial console program
hey guys i know all of can help me here. Program is about user enters a number at run time and output should give the factorial.
thanx in advance.
I feel error is really simple but couldnt sort it out.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class NumberFactorial
{
public static void main(String args[])
{
int number;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number");
number = Integer.parseInt(br.readLine());
int factorial = number;
for(int i =(number-1);i>1;i--)
{
factorial=factorial*i;
}
}
catch(NumberFormatException ne)
{
System.out.println("Number Format Exception"+ne);
System.exit(0);
}
catch(IOException ioe)
{
System.out.println("Input Exception Error"+ioe);
System.exit(0);
}
System.out.println("Factorial of number is:" +factorial);
}
}