Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Class factorial

1/1

import java.io.*;
public class factorial
{
int n;
int f;
DataInputStream d=new DataInputStream(System.in);
public factorial()
{
n=0;
f=0;
}
int fact(int num)//recursive method
{
if(num==0)//base case
{
return 1;
}
return (num*fact(num-1));//recursive case
}
void getnum(int x)
{
n=x;
f=fact(n);
System.out.println("FACTORIAL "+f);
}
void main()throws IOException
{
System.out.println("ENTER NUMBER");
int a=Integer.parseInt(d.readLine());
getnum(a);
}//end of main
}//end of class

Jan 16, 2015 11:18:27 PM

factoria1.main();
ENTER NUMBER
5
FACTORIAL 120
factoria1.main();
ENTER NUMBER
6
FACTORIAL 720

You might also like