I have the following problems with my program:
1. it's not outputting the last String entered: "I".
2. My twice and thrice duplication seems to be OK, but when I verified it said to be sure that it duplicates twice if it's even thrice if it's odd.
Please help. Thanks.
package com.codegym.task.task07.task0727;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Changing functionality
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
while (true) {
String s = reader.readLine();
if (s.isEmpty()) break;
list.add(s);
}
ArrayList<String> list2 = new ArrayList<String>();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).length() % 2 == 0)
{
list2.add(list.get(i) + " " + list.get(i));
}
else if(list.get(i).length() % 3 == 0)
{
list2.add(list.get(i) + " " + list.get(i) + " " + list.get(i));
}
}
for(String x : list2)
{
System.out.println(x);
}
}
}