AlexKondov

Java Largest Sequence of Equal Strings

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