Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.nio.file.Files;
  3. import java.nio.file.Paths;
  4.  
  5. public class NiceStringPart2 {
  6. static char previous = ' ';
  7. static char previous2 = ' ';
  8. static char previousPrevious = ' ';
  9. static int count = 0;
  10. static int index = 0;
  11. static int index2 = 0;
  12. static boolean sandwich = false;
  13. static boolean doublePair = false;
  14. public static void main(String[] args) throws IOException {
  15. // TODO Auto-generated method stub
  16. for(String line : Files.readAllLines(Paths.get("C:/Users/Gregorio21/Desktop/Advent.txt"))){
  17. if(sandwich && doublePair){
  18. count ++;
  19. }
  20. sandwich = false;
  21. doublePair = false;
  22. previous = ' ';
  23. previous2 = ' ';
  24. previousPrevious = ' ';
  25. index = 0;
  26. System.out.println(count);
  27. for(char chars : line.toCharArray()){
  28. if(chars == previousPrevious){
  29. sandwich = true;
  30. }
  31.  
  32. for(char chars2 : line.toCharArray()){
  33. if((index2 - index > 1 && chars2 == chars)){
  34. if((previous == previous2)){
  35. doublePair = true;
  36. }
  37. }
  38. previous2 = chars2;
  39. index2 ++;
  40. }
  41. previousPrevious = previous;
  42. previous = chars;
  43. index2 = 0;
  44. index ++;
  45. }
  46. }
  47. System.out.println(count);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement