public class FindFactorial {
int a=0;
FindFactorial(int i){
a=i;
}
int displayFact(FindFactorial f){
if(f.a<1)
return 1;
else{
f.a--;
return (f.a+1)*displayFact(f);
}
}
}
public class Main {
public static void main(String[] args){
FindFactorial f1 = new FindFactorial(3);
System.out.println("factorial ="+ f1.displayFact(f1));
}
}
Output:
No comments:
Post a Comment