Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FRQSolutionStringRuns {
- public static void main(String[] args) {
- String s="laaah jjjjj,trddoooooo!";
- String maxRunChar="";
- int maxRun1=0;
- int runCount1=0;
- for(int i=0; i<s.length(); i++){
- //aaaah jjjjj,trddoooooo!
- String previous="";
- String next="";
- String current=s.substring(i,i+1);
- if(i>0) {
- previous = s.substring(i - 1, i);
- }
- if(i<s.length()-1) {
- next= s.substring(i + 1, i + 2);
- }
- if(current.equals(next)){
- runCount1++;
- }else if(current.equals(previous)){
- runCount1++;
- if(runCount1>maxRun1) {
- maxRun1 = runCount1;
- maxRunChar = current;
- }
- runCount1=0;
- }
- }
- System.out.printf("Max Run: %d, MaxRunChar: %s\n",maxRun1, maxRunChar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement