import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; class DayTwo { public static void main(String[] args) { int count1 = 0; try { File inputFile = new File("input.txt"); Scanner readFile = new Scanner(inputFile); while (readFile.hasNextLine()) { int count2 = 0; String whale = readFile.nextLine(); int lowerBound = Integer.parseInt(whale.substring(0, whale.indexOf("-"))); int upperBound = Integer.parseInt(whale.substring(whale.indexOf("-") + 1, whale.indexOf(":") - 2)); char inputKey = whale.charAt(whale.indexOf(":") - 1); String password = whale.substring(whale.indexOf(":") + 1); char[] passwordChar; passwordChar = password.toCharArray(); for (int i = 0; i < passwordChar.length; i++) { if (inputKey == passwordChar[i]) { count2++; } } if (passwordChar[lowerBound] == inputKey ^ passwordChar[upperBound] == inputKey) { count1++; } System.out.println(lowerBound); System.out.println(upperBound); System.out.println(inputKey); System.out.println(password); System.out.println(count1); } readFile.close(); } catch (FileNotFoundException e) { System.out.println("crap"); } } }