Factorial Program in Java

 class facto  
 {  
      int fact(int n)  
      {  
           if (n==1)  
           {  
                return n;  
           }  
           else   
           {  
                int temp=n*fact(n-1);  
                return temp;  
           }  
      }  
 }  
 class factorial   
 {  
      public static void main(String[] args)   
      {  
           facto obj=new facto();  
           int n=5;  
           int k=obj.fact(n);  
           System.out.println("Hello World!"+k);  
      }  
 }  

Post a Comment

0 Comments