Actual question today, not a proofreading error;
I’m a little stumped. It says I need to remove “r” words but I did that, so I thought. I have a feeling it’s a logic order issue but it should work the output in the compiler is ok? Any help is gladly accepted,
package com.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
R or L
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("rose"); // 0
list.add("love"); // 1
list.add("lyre"); // 2
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
for (int i = 0; i < list.size(); i++) {
String s = list.get(i);
if (s.contains("l") && (s.contains("r"))) {
continue;
}
if (s.contains("l") && !(s.contains("r"))) {
list.add(i+1,s);
}
if (s.contains("r") && !(s.contains("l"))) {
list.remove(s); }
System.out.println(list.get(i));
}
return list;
}
}