but why task not accepting the code? whats wrong? and i from phone writing and there very often window with text long time ... . and not compile.
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"); // 0
list.add("love_1"); // 1
list.add("lyre_2"); // 2
list = fix(list);
// "love" 2 all 3
for (String s : list) {
System.out.println(s);
}
}
//---------------
public static ArrayList<String> fix(ArrayList<String> list) {
ArrayList<String> st = new ArrayList <String>();
// st.add("lyre");
int i = 0, c = list.size();
int a1, a2;
for( i = 0 ;i < c; )
{
a1 = 0; a2 = 0;
// char compare
for (int x = 0; x < list.get(i).length(); x++)
{
char ch = list.get(i).charAt(x);
if ( ch == 'r' ) a1 = 1;
if ( ch == 'l' ) a2 = 1;
} // for x
if (!(st.size() == 0)) {
for (int x1 = 0; x1 < st.size();x1++)
{
if (list.get(i).equals(st.get(x1) ) )
{
i++;
} else
{
if ((a1 == 1) && ( a2 == 0)) { list.remove(i); }
if ((a1 == 0) && ( a2 == 1)) { list.add(list.get(i)); st.add(list.get(i));i++; }
if ((a1 == 1) && ( a2 == 1)) { i++; }
// System.out.println(" false ");
}
}
} else {
if ((a1 == 1) && ( a2 == 0)) { list.remove(i); }
if ((a1 == 0) && ( a2 == 1)) { list.add(list.get(i)); st.add(list.get(i));i++; }
}
}
return list;
}
}