The desired loop I want is to have the program loop until the accepted condition is met. I have tried to switch around the operators to get the desired loop I want. I was certain that this was the correct code to meet my conditions but this causes my java console not to appear at all!
Can someone explain what I am doing wrong please?
while (total % 5 != 0) {
System.out.println("Enter 3 a-z characters");
Scanner scan = new Scanner(System.in);
Pattern pattern = Pattern.compile("^[a-zA-Z]$");
for (int i = 0; i < 3; i++) {
String input = scan.nextLine();
while (!pattern.matcher(input).matches()) {
System.out.println("Incorrect");
input = scan.nextLine();
}
int letter = input.charAt(0);
if (letter >= 97 && letter <= 122) {
total += letter - 96;
} else if (letter >= 65 && letter <= 90) {
total += letter + 36;
}
}
if (total % 5 == 0) {
System.out.println("accepted");
} else {
System.out.println("not accepted");
scan.close();
}
}
}
}