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) { int j=0; ArrayList<String> list1 = new ArrayList<String>(); list1.addAll(list); for(int i=0;i<3;i=j) { if(list1.get(i).contains("r")&&!(list1.get(i).contains("l"))){ list1.remove(i); j=0; } if(!(list1.get(i).contains("r"))&&list1.get(i).contains("l")){ list1.add(list.get(i)); j=j+1; } if(list1.get(i).contains("r")&&list1.get(i).contains("l")){ continue; } if(!(list1.get(i).contains("r"))&&!(list1.get(i).contains("l"))){ continue; } } return list1; } } //1.The program must not read data from the keyboard. //2.The fix method should remove all words containing the letter "r" from the list. There is an exception: words containing both "r" and "l" should be left alone. //3.The fix method must duplicate words containing the letter "l" (add another instance of this word to the list). There is an exception: words containing both "l" and "r" should not be duplicated. //4.The fix method should not do anything with words that contain both "l" and "r". //5.The fix method should not do anything with words that don't contain either "l" or "r".