File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Roadmap/06 - RECURSIVIDAD/java Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ public class reto_6 {
3+
4+ public static void main (String [] args ) {
5+
6+ numRecursivo (0 );
7+ System .out .println ("\n **********************" );
8+ int factorial = factorial (5 );
9+
10+ System .out .println ("Factorial: " + factorial +"\n " );
11+
12+ int Fibonacci = Fibonacci (5 );
13+
14+ System .out .println ("El numero es: " + Fibonacci );
15+ }
16+
17+ public static void numRecursivo ( int n ){
18+
19+ if (n > 100 ) {
20+ return ;
21+ }
22+ System .out .println (n );
23+ numRecursivo (n +1 );
24+
25+
26+ }
27+ public static int factorial ( int n ){
28+
29+ if (n == 0 || n == 1 ) {
30+ return 1 ;
31+ }
32+ return n * factorial (n - 1 );
33+ }
34+
35+ public static int Fibonacci ( int n ){
36+
37+ if (n <= 1 ) {
38+ return n ;
39+ }else {
40+ return (Fibonacci ( n - 1 ) + Fibonacci ( n - 2 ));
41+ }
42+ }
43+ }
44+
You can’t perform that action at this time.
0 commit comments