Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class LongestBlockInString {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int currentCount = 1 ;
- int maxCount = 0 ;
- char maxChar = ' ';
- String string = scanner.nextLine();
- char[] chars = new char[string.length()];
- for(int i = 0 ; i < string.length(); i++) {
- chars[i] = string.charAt(i);
- }
- for (int i = 0 ; i < chars.length - 1; i++){
- if (chars[i] == chars[i+1]){
- currentCount++;
- }
- else currentCount = 1;
- if (currentCount > maxCount) {
- maxCount = currentCount;
- maxChar = chars[i];
- }
- }
- for (int i = 0 ; i < maxCount;i++) {
- System.out.print(maxChar);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment