package com.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
love
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("lyre"); // 0
list.add("love"); // 1
list.add("rl"); // 2
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
// write your code here
String l = "l";
String r = "r";
ArrayList<String> Rlist = new ArrayList<String>();
Rlist.addAll(list);
for(int i=0;i<Rlist.size();i++){
String w = Rlist.get(i);
if(w.contains(l) && w.contains(r)){
}else if(!w.contains(l) && !w.contains(r)){
}else if(w.contains(r)){
list.remove(i);
}else if(w.contains(l)){
list.add(i-1,w);
}
}
return list;
}
}
package com.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
R or L
1. Create a list of words and populate it yourself.
2. The fix method should:
2.1. remove all words containing the letter "r" from the list
2.2. duplicate all words containing the letter "l".
2.3. if a word contains both "r" and "l", then leave it unchanged.
2.4. don't do anything to other words.
For example:
rose
lyre
love
Output:
lyre
love
love
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("lyre"); // 0
list.add("love"); // 1
list.add("rl"); // 2
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
// write your code here
String l = "l";
String r = "r";
ArrayList<String> Rlist = new ArrayList<String>();
Rlist.addAll(list);
for(int i=0;i<Rlist.size();i++){
String w = Rlist.get(i);
if(w.contains(l) && w.contains(r)){
}else if(!w.contains(l) && !w.contains(r)){
}else if(w.contains(r)){
list.remove(i);
}else if(w.contains(l)){
list.add(i-1,w);
}
}
return list;
}
}