Dear all,
can someone help me with my code, please? I don't understand the error "infinite loop".
Kind regards,
Gudrun
package de.codegym.task.task07.task0716;
import java.util.ArrayList;
import java.lang.*;
/*
R oder L
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> liste = new ArrayList<>();
liste.add("Rose"); // 0
liste.add("Leier"); // 1
liste.add("Liebe"); // 2
liste.add("Geiger"); //3
liste.add("geliefert"); //4
liste.add("Tuch"); //5
liste = korrigieren(liste);
for (String s : liste) {
System.out.println(s);
}
}
public static ArrayList<String> korrigieren(ArrayList<String> liste) {
// schreib hier deinen Code
for (int i = 0; i < liste.size(); ) {
String wort = liste.get(i);
boolean lda = wort.contains("l") || wort.contains("L");
boolean rda = wort.contains("r") || wort.contains("R");
if (lda & rda) { //r und l da: nichts machen
i++;
}
if (lda & !rda) { //l da: das Wort duplizieren
liste.add(i + 1, wort);
i = i + 2;
}
if (rda & !lda) { //r da: Wort entfernen
liste.remove(i);
i = i;
}
}
return liste;
}
}