Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyProgram
- {
- public static void main(String[] args)
- {
- System.out.println("e5");
- longestStreak("teeeeest");
- }
- public static void longestStreak (String str) {
- char char1;
- char char2 = ' ';
- int count = 1;
- char letter = ' ';
- int max = Integer.MIN_VALUE;
- for (int i = 0; i < str.length(); i++) {
- char1 = str.charAt(i);
- if(i < str.length()-1) {
- char2 = str.charAt(i+1);
- }
- if (char1 == char2) {
- count++;
- }
- else {
- if(max >= Math.max(max, count)) {
- letter = char1;
- }
- max = Math.max(max, count);
- count = 1;
- }
- }
- System.out.println(letter + " " + max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement