
Transformada de algoritmo iterativo
Publicado por Lucía (1 intervención) el 24/10/2019 12:22:32
A ver estoy intentando transformar este algoritmo iterativo funcional (en java 11):
en este utilizando un while obligatoriamente:
pero no sé qué fallos tengo alguien sabría decirmelos? Gracias!!
1
2
3
4
5
public static List<Integer> f (List<Integer> l) {
// return l.stream()
// .filter(e -> (e%2 == 0))
// .map(e -> e*e)
// .collect(Collectors.toList());
en este utilizando un while obligatoriamente:
1
2
3
4
5
6
7
8
9
10
11
public static List<Integer> f (List<Integer> l1){
List<Integer> ls = new List<>();
Integer i=0;
while(i<l1.size()) {
if (l1[i]%2 == 0) {
ls= ls+ l1[i]^2;
i++;
}
return ls;
}
pero no sé qué fallos tengo alguien sabría decirmelos? Gracias!!
Valora esta pregunta


0