I have a string like:
Hello how how how are are you you?
I love cookies cookies, apples and pancakes pancakes.
I wish for an output:
Hello how are you?
I love cookies, apples and pancakes.
Till now I have coded:
String[] s = input.split(" "); String prev = s[0]; String ans = prev + " "; for (int i = 1; i < s.length; i++) { if (!prev.equals(s[i])) { prev = s[i]; ans += prev + " "; } } System.out.println(ans); I get outputs as:
Hello how are you you?
I love cookies cookies, apples and pancakes pancakes.
I need some help with the logic for , . ! ? ...
cookiesis not equal tocookies,. I need to help with the logic so that my program takes it as the same and adds the one with the punctuation