AlexKondov

Java Sequences of Equal Strings

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