Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SequencesofEqualStrings {
  4. public static void main(String[] args) {
  5. Scanner str = new Scanner(System.in);
  6. String input = str.nextLine();
  7. String[] words = input.split(" ");
  8. if (words.length == 1) {
  9. System.out.println(words[0]);
  10. }
  11. for (int i = 0; i < words.length - 1; i++) {
  12. if (words[i].equals(words[i + 1])) {
  13. System.out.print(words[i] + " ");
  14.  
  15. } else {
  16. System.out.println(words[i]);
  17. }
  18. }
  19. if (words.length != 1) {
  20. System.out.print(words[words.length - 1]);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement