-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursividad.java
More file actions
39 lines (23 loc) · 771 Bytes
/
Recursividad.java
File metadata and controls
39 lines (23 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class Recursividad {
public static int funRec(int[] array, int index, int max){
if(index != array.length){
if(array[index] > max){
max = funRec(array, index + 1, array[index]);
}else{
max = funRec(array, index + 1, max);
}
}
return max;
}
public static int funRec2(int[] array, int index){
int max = Integer.MIN_VALUE;
if(index != array.length){
max = Math.max(array[index], funRec2(array, index + 1));
}
return max;
}
public static void main(String[] args){
int[] array = {1, 6, 8, -34, 21, 3};
System.out.println("Número máximo es: "+ funRec(array, 3, array[0]));
}
}