0

Urgent help

Why is this code returnIng many spaces. I have tried all i can https://code.sololearn.com/cQ5FoHjqP2PO/?ref=app

15th Sep 2020, 8:18 AM
TheAdeyemiOlayinka 💗
TheAdeyemiOlayinka 💗 - avatar
6 Respuestas
+ 2
The problem is in line 25. When char s in message is space, your if check returns true 26 times. You should put a break there like this: else if (s == space.charAt(0)){ sb.append(space.charAt(0)); break; }
15th Sep 2020, 6:47 PM
Aleksandrs
Aleksandrs - avatar
+ 1
You should put a break at end of every if() here alternatively at final correction of spaces you can use // .split("\\s"); .split("\\s+"); // added +
15th Sep 2020, 9:02 PM
zemiak
0
what input is causing problems?
15th Sep 2020, 12:42 PM
zemiak
0
zemiak every input. It returns many spacea
15th Sep 2020, 12:43 PM
TheAdeyemiOlayinka 💗
TheAdeyemiOlayinka 💗 - avatar
0
Aleksandrs Kalinins Thanks, I have seen it
15th Sep 2020, 8:52 PM
TheAdeyemiOlayinka 💗
TheAdeyemiOlayinka 💗 - avatar
0
zemiak funny enough, I never thought of adding a break. My mistake
15th Sep 2020, 9:03 PM
TheAdeyemiOlayinka 💗
TheAdeyemiOlayinka 💗 - avatar