Advertisement
fit_max

Longest Block in string 60%

Dec 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Testing {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. String input = sc.nextLine();
  7. char[] arrOfInput = input.toCharArray();
  8. int length = 1;
  9. int start = 0;
  10. int bestlength=0;
  11. int beststart=0;
  12. for (int i = 1; i < arrOfInput.length; i++)
  13. {
  14. if (arrOfInput[i - 1] == arrOfInput[i])
  15. {
  16. length++;
  17. continue;
  18. }
  19. if (bestlength<length)
  20. {
  21. bestlength = length;
  22. beststart = start;
  23. }
  24. length = 1;
  25. start = i;
  26. }
  27.  
  28. for (int j = beststart; j < bestlength + beststart; j++)
  29. {
  30. System.out.print(arrOfInput[j]);
  31.  
  32. }
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement