Changing functionality

  • 5
An ancient completed task is gathering dust in the archive. It requires you to enter strings until an empty string is entered. Then all letters in the strings are converted to uppercase. Let's modernize the task: The program should build a new list. If a string has an even number of letters, then the string is duplicated. If the number of letters is odd, then the string is repeated three times. We'll leave the string input part unchanged.
You can't complete this task, because you're not signed in.
Comments (17)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Switch/Cypher
Level 25, Bexleyheath, United Kingdom
14 September 2020, 10:18
Clarifying this: "The program should display as many strings as are entered" Change each original entry in the index to match the conditions. If index(0) had an odd lettered word then index(0) needs to return that same word repeated 3 times. The word should not be repeated three times at different indices.
Carl Bulger
Level 8, Valletta, Malta
8 September 2020, 09:08
Don't overthink this exercise. A simple change in the last for loop is all that is needed to pass the validation
Roman Grygorczuk
Level 19, Cracow, Poland
12 November 2020, 21:35
OMG! They said "the program build new list" so I have created even and odd arraylists.....no needed. The solution is very primitive I would say.
ImDevin
Level 9, Old Town, United States
26 April, 14:23
Thx for this super tip. Without it, I would've gone down the wrong path & would've spent ungodly amount of time trying to solve it.
Karas
Level 19, Tampa, United States
8 September 2020, 00:12
Input: Dog Me Cat Output: DOG DOG DOG ME ME CAT CAT CAT Both task combined have to give you the result basically. Confusing but simple.
ImDevin
Level 9, Old Town, United States
26 April, 14:23
This helped too!
AlfredW
Level 23, Denver, United States
2 July 2020, 18:58
This was very poorly explained. The part that was not clear to me was that the new list of strings should be the same size as the old list of strings but with each string changed. So if list1(0) = "wer" then list2(0) should be "wer wer wer". Or if list1(1) is "bo" then list2(1) should be "bo bo". This is as opposed to adding new items to the list where list(1) ="ert" creates or adds 2 more items for list2, list2(1) = "ert", list2(2) = "ert" and list2(3) = "ert". This had me lost for the longest time. More clarity in the assignment would have been better.
Peter Karanyi
Level 9, Cowplain, United Kingdom
13 June 2020, 08:28
I managed my code to pass but I am very pissed, because just like in one of the previous tasks String.isEmpty() again in IntelliJ worked when I pressed ENTER, in Codegym it didn't. Again an error here ... So again just like in that previous lesson I had to put if( s == null || s.isEmpty()) to make Codegym to let it run without an error. Dear Codegym Team, could you please sort this out?
Daniel
Level 8, Vienna, Austria
10 June 2020, 15:28
I am so angry right now. The conditions are stupidly written. I was creating a new single list with odd and even numbers and was trying to display the strings as in description. Lost hours trying to figure out how to do it when I gave up and looked into help. Turns out you can create two lists. People who wrote the conditions are really STUPID.
Tonatiuh
Level 12, Mexico, Mexico
20 November 2019, 21:47
The second requirement was very confusing: "The program should display as many strings as are entered." My program worked well with:
String s = reader.readLine();
 if (s == null) break;
But I needed to change it to:
if (s.length() == 0) break;
¿Does somebody understand the real difference?
Roman
Level 41
21 November 2019, 07:38
An empty string (by pressing Enter)! "Empty" is not null ! Try to test with the code :
public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    ArrayList list = new ArrayList<>();
    for (int i = 0; i < 2; i++) {
        String s = reader.readLine();
        list.add(s);
    }

    list.add(null);

    for (String s : list) {
        System.out.println(s);
    }
}
Input :
test // Enter
// Enter
Output :
test
// Empty string (not null!)
null // in the code list.add(null);
Tonatiuh
Level 12, Mexico, Mexico
21 November 2019, 23:23
I see now. Thanks a lot!
Marcin
Level 20, Edinburgh, United Kingdom
24 September 2019, 19:42
/* Comment has been deleted */
Jack Tyler
Level 11, Minsk, Belarus
13 August 2019, 15:34
Whe the program doesn't compile by default? Error is: java.lang.NullPointerException at com.codegym.task.task07.task0727.Solution.main(Solution.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...
Ashutosh Kumar
Level 18, Delhi, India
16 August 2018, 22:16
My code is getting verified,but I am facing NullPointerException,any hint on how to proceed
Eren
Level 41, Shiganshina
17 August 2018, 06:18
Please create a question in the "Help" section and show your code there.
Muhammad Vahhaaj
Level 19, Rawalpindi, Pakistan
4 July 2019, 06:03
use 1 or 2 blank lines