Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- public class NiceStringPart2 {
- static char previous = ' ';
- static char previous2 = ' ';
- static char previousPrevious = ' ';
- static int count = 0;
- static int index = 0;
- static int index2 = 0;
- static boolean sandwich = false;
- static boolean doublePair = false;
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- for(String line : Files.readAllLines(Paths.get("C:/Users/Gregorio21/Desktop/Advent.txt"))){
- if(sandwich && doublePair){
- count ++;
- }
- sandwich = false;
- doublePair = false;
- previous = ' ';
- previous2 = ' ';
- previousPrevious = ' ';
- index = 0;
- System.out.println(count);
- for(char chars : line.toCharArray()){
- if(chars == previousPrevious){
- sandwich = true;
- }
- for(char chars2 : line.toCharArray()){
- if((index2 - index > 1 && chars2 == chars)){
- if((previous == previous2)){
- doublePair = true;
- }
- }
- previous2 = chars2;
- index2 ++;
- }
- previousPrevious = previous;
- previous = chars;
- index2 = 0;
- index ++;
- }
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement