package pl.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
R czy L
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> lista = new ArrayList<String>();
lista.add("rosa"); // 0
lista.add("lira"); // 1
lista.add("luz"); // 2
lista = napraw(lista);
for (String s : lista) {
System.out.println(s);
}
}
public static ArrayList<String> napraw(ArrayList<String> lista) {
// tutaj wpisz swój kod
int iSize = lista.size() -1;
for (int i = 0; i < iSize;){
Boolean iFind1 = lista.get(i).contains("r");
Boolean iFind2 = lista.get(i).contains("l");
if (iFind1 && iFind2) i++;
else if (!iFind1 && !iFind2) i++;
else if (iFind1) lista.remove(i);
else if (iFind2) {
lista.add(lista.get(i));
i++;
}
}
return lista;
}
}
works fine but codegym doesn't let go...
Dyskutowane
Komentarze (2)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Misiu
1 grudnia 2020, 15:55
I entered only one word: rosa
Output:
rosa
0
Guadalupe Gagnon
1 grudnia 2020, 15:52
I tried your code with a list that had:
["rosa", "rosa", "rosa"]
And it threw an IndexOutOfBoundsException. Revisit the code so that it does not throw any exceptions no matter the contents or size of the list passed to the method.
0