Advertisement
Masovski

[Java Basics][Collections-HW] 03.Largest Seq of Equal String

May 24th, 2014
308
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 LargestSeqOfEqualStrings {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.        
  8.         int count = 1;
  9.         int max = 1;
  10.        
  11.         String input = sc.nextLine();
  12.         String[] strArr = input.split(" ");
  13.         String largest = strArr[0];
  14.        
  15.  
  16.         for (int i = 1; i < strArr.length; i++) {
  17.             if (strArr[i].equals(strArr[i - 1])) {
  18.                 count++;
  19.                 if (count > max) {
  20.                     max = count;
  21.                     largest = strArr[i];
  22.                 }
  23.             } else {
  24.                 count = 1;  
  25.             }
  26.         }
  27.  
  28.         for (int i = 0; i < max; i++) {
  29.             System.out.print(largest + " ");
  30.         }
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement