public class CaesarCipher {
public static void main(String[] args) {
String answer = "";
do {
String Phrase = "";
Scanner scan = new Scanner(System.in);
System.out.println("Type in a phrase");
String phrase = scan.nextLine();
System.out.println("Your Phrase was " + phrase);
for (int i = 0; i < phrase.length(); i++) {
char charAt = phrase.charAt(i);
System.out.println("The " + (i) + " character is " + charAt);
}
System.out.print("Would you like to try again? (Yes/No).");
answer = scan.next();
scan.close();
} while (answer.equals("Yes"));
System.out.println("Thank you, have a nice day.");
}
}
I can get this to go through and even end correctly when the user responds "no", but every time I say yes and re run it. The program crashes after it asks for another input ("type in a phrase"). It says that there is nothing for the scanner to scan even though it hasn't given me an opportunity to enter anything.