Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LongestBlockInString {
  4. public static void main(String[] args){
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String input = scanner.nextLine();
  8. // System.out.print(input.length());
  9.  
  10. int maxCount = 0;
  11. char maxSequentChar = ' ';
  12. int count = 1;
  13.  
  14. if(input.length() <= 1){
  15. System.out.println(input);
  16. }
  17.  
  18. for (int i = 0; i < input.length() - 1; i++){
  19. if(input.charAt(i) == input.charAt(i + 1)){
  20. count++;
  21. }else {
  22. count = 1;
  23. }
  24. if(count > maxCount){
  25. maxCount = count;
  26. maxSequentChar = input.charAt(i);
  27. }
  28. }
  29. for(int i = 0; i < maxCount; i++){
  30. System.out.print(maxSequentChar);
  31. }
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement