package com.codegym.task.task07.task0716;
import java.util.ArrayList;
public class Solution {
/*
R or L
*/
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("rose"); // 0
list.add("measure"); // 1
list.add("digit");//2
list.add("lyre"); // 3
list.add("royal");//4
list.add("love");//5
list.add("wade");//6
list.add("bark");//7
list = fix(list);//8
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
// write your code here
//char[] instructions = new char[list.size()];
ArrayList<String> alist = new ArrayList<String>();
ArrayList<String> secondList = new ArrayList<String>();
alist.addAll(list);
boolean isOther = true;
//iterate through the list of words
for(int i=0; i<alist.size(); i++){
//make the word characters all lowercase for comparison
String word = alist.get(i).toLowerCase();
//instructions given for ("r" and "l"), "r", and "l"
if(word.contains("r") && !(word.contains("l"))){
isOther = true;
continue;
}else if(word.contains("r") && word.contains("l")){
secondList.add(word);
isOther = true;
}else if(word.contains("l") && !(word.contains("r"))){
secondList.add(word);
secondList.add(word);
isOther = true;
}else if(isOther){
secondList.add(word);
}
}
return secondList;
}
}
hidden #10362262
Level 9
Why doesn't this code Pass? The output is correct when using "Run"
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Rohit Aggarwal Backend Developer at Tekion Corp.
9 August 2019, 03:52
From what I understand, you don't need the isOther variable, and you can simply remove the last elseif condition, and restructure something this
0