06-04-2011, 01:12 PM
Code:
import java.io.*;
class Factorial
{
int fact(int n)
{
if(n<=1)
return 1;
else
return (n*fact(n-1));
}
}
class Newfact
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter the number");
int i=Integer.parseInt(dis.readLine());
Factorial f=new Factorial();
System.out.println("Factorial is"+f.fact(i));
}
}
OUTPUT
E:\ 5BCA-B\lijo\java >javac Newfact.java
Note: Newfact.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
E:\ 5BCA-B\lijo\java >java Newfact
Enter the number
5
Factorial is 120