In my program, the loop asks and executes correctly on the first loop. Upon starting the second iteration and so forth of the loop, it skips asking the user for a message to be encrypted. Why is that?
public void startProgram() {
boolean quit = false;
while (!quit) {
String plaintext = new String();
System.out.println("Enter a message to be encrypted.");
plaintext = sc.nextLine();
System.out.println("Now enter a shift value for your message.");
int i = sc.nextInt();
cc.encryptMessage(i, plaintext);
System.out.println("Here is your encrypted message: ");
cc.printEncyrption();
System.out.println();
System.out.println("Here is your original plaintext message: ");
cc.decryptMessage(i);
cc.printPlaintext();
System.out.println("\n");
}
}
Here is a sample of what happens in the output:
Enter a message to be encrypted.
the sky
Now enter a shift value for your message.
4
Here is your encrypted message:
xli woc
Here is your original plaintext message:
the sky
Enter a message to be encrypted.
Now enter a shift value for your message.
At the beginning of the second iteration of the loop, it doesn't allow the user to input a message to be encrypted. I believe it has something to do with the nextLine() method.