I get the desired output but i cant pass it. Some help please?
package com.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
R or L
Create a list of words and populate it yourself.
The fix method should:
remove all words containing the letter "r" from the list
duplicate all words containing the letter "l".
if a word contains both "r" and "l", then leave it unchanged.
don't do anything to other words.
}
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<>();
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) {
// write your code here
for (int i = 0; i < 2; i++) {
if (list.get(i).contains("l") && !(list.get(i).contains("r"))) {
list.add(i+1,list.get(i));
}else if (list.get(i).contains("l") && list.get(i).contains("r")) {
continue;
}
}
for (int i = 0; i < 2; i++) {
if (list.get(i).contains("r") && !list.get(i).contains("l")) {
list.remove(i);
}else if (list.get(i).contains("l") && list.get(i).contains("r")) {
continue;
}
}
return list;
}
}