1 / 19

Recursive Factorial Demo

Recursive Factorial Demo. pubic class Factorial { public static int fact ( int n ) { if ( n == 0 ) return 1 ; else return n * fact ( n - 1 ); } public static void main ( String [] args ) { System . out . println ( fact ( 3 )); } }. static int fact ( int n ) {

perrin
Download Presentation

Recursive Factorial Demo

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recursive Factorial Demo pubic class Factorial { public staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } publicstaticvoid main(String[] args) { System.out.println(fact(3)); } }

  2. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) n = 3 environment

  3. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) n = 3 environment

  4. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) n = 3 environment

  5. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) n = 3 n = 2 environment environment

  6. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) n = 3 n = 2 environment environment

  7. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) n = 3 n = 2 environment environment

  8. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) n = 3 n = 2 n = 1 environment environment environment

  9. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) n = 3 n = 2 n = 1 environment environment environment

  10. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) n = 3 n = 2 n = 1 environment environment environment

  11. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(0) n = 3 n = 2 n = 1 n = 0 environment environment environment environment

  12. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(0) n = 3 n = 2 n = 1 n = 0 environment environment environment environment

  13. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(0) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } n = 0 n = 3 n = 2 n = 1 environment environment environment environment 1

  14. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) n = 3 n = 2 n = 1 environment environment environment 1 1

  15. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(1) n = 3 n = 2 n = 1 environment environment environment 1 1 1

  16. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) n = 3 n = 2 environment environment 1 2

  17. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(2) n = 3 n = 2 environment environment 2 1 2

  18. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) n = 3 environment 3 2

  19. staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } fact(3) n = 3 environment 3 2 public class Factorial { public staticint fact(int n) { if(n ==0)return1; elsereturn n * fact(n-1); } publicstaticvoid main(String[] args) { System.out.println(fact(3)); } } % java Factorial 6 6

More Related