I was finally able to get the example output result in the exercise but it is still denying me a passing mark on two categories. Can someone please help me understand what I am doing wrong here?
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++){
if (list.get(i).contains("l") && !list.get(i).contains("r")) {
System.out.println(list.get(i));
}
}
for (int j = 0; j < list.size(); j++){
if (list.get(j).contains("r") && !list.get(j).contains("l")){
list.remove(list.get(j));
}
}
return list;
}
}