Advertisement
MayurTolani

factorial with full encapsulation

Aug 28th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. class Fact
  2. {
  3.     private int fact=1;
  4.  
  5.     public void calcFact(int n)
  6.     {  
  7.         for(int i=n;i>1;i--)
  8.         fact=fact*i;   
  9.     }
  10.  
  11.     public int getFact()
  12.     {
  13.         return fact;
  14.     }
  15.  
  16. }
  17.  
  18. class TestFact
  19. {
  20.     public static void main(String... args)
  21.     {
  22.         Fact f=new Fact();
  23.         f.calcFact(3);
  24.         System.out.println("factorial of the number is = " + f.getFact() );
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement