Java Program To Find the factorial of a given number by using function/Method.
import java.io.*;
class Factorial
{
 public static void main(String arg[])
 {
  try
  {
   int n;
   System.out.print(" Enter A Number : ");
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   n=Integer.parseInt(br.readLine());
   Factorial ob=new Factorial();
   int g=ob.fact(n);
   System.out.println(" Factorial Of the Number : "+n+" is "+g);
  }catch(Exception e){}
 }
 int fact(int n)
 {
  if(n==1)
  return 1;
  else
  {
  return(n*fact(n-1));
  }
 }
} 
| 
 
Loading...
 
 | 


Comments :
Post a Comment