Factorial Example : Java

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 Number " +a+ ":");
for (int i= 1; i<=a; i++){
fact=fact*i;
}
System.out.println(fact);
}
catch (Exception e){}
}
}


0 comments: