Venciity

[SoftUni Java] Collections Basic - 02.SequencesEqualStrings

May 28th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _02_SequencesEqualStrings {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         try(Scanner reader = new Scanner(System.in)){
  8.            
  9.             String input = reader.nextLine();
  10.            
  11.             String[] strArray = input.split(" ");
  12.            
  13.             String lastElement = strArray[0];
  14.            
  15.             for (String element : strArray) {
  16.                    
  17.                 if (!element.equals(lastElement)) {
  18.                     System.out.println();
  19.                 }
  20.                                
  21.                 System.out.print(element + " ");
  22.                
  23.                 lastElement = element;
  24.                
  25.             }
  26.         }
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment