import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException
{
int num;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
if(num==0)
{
System.out.println("Factorial of 0 is: 1");
}
else
{
System.out.println("Factorial of "+num+" is: "+fact(num));
}
}
public static int fact(int num)
{
if(num==1)
return num;
else
return num*fact(num-1);
}
}
class Factorial
{
public static void main(String args[]) throws IOException
{
int num;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
num=Integer.parseInt(br.readLine());
if(num==0)
{
System.out.println("Factorial of 0 is: 1");
}
else
{
System.out.println("Factorial of "+num+" is: "+fact(num));
}
}
public static int fact(int num)
{
if(num==1)
return num;
else
return num*fact(num-1);
}
}
No comments:
Post a Comment