I've searched around and can't find a solution to my problem. For one of my courses I'm tasked with writing a simple console email system. When the user is prompted for a message body, the string variable that holds the input only takes one word, not the whole message. I read that I should use readLine(), but when the program prompts the user to enter a message body, it completely skips input for that segment. To remedy this, I read that I should place a skip("\n") before I read the line. Now, however, the program doesn't end after the user presses Enter. It just keeps taking input and won't let me do anything.
Here is a bit of the code to help:
Scanner in = new Scanner(System.in);
//Declare variables
String subject, reciepent, message = "";
//Get subject
System.out.println("> Enter subject: ");
subject = in.next();
//Get reciepent
System.out.println("> Enter reciepent: ");
reciepent = in.next();
//Get message
System.out.println("> Enter message: ");
in.skip("\n");
message = in.nextLine();
//Print out message to verify user input
System.out.println("> " + message);
I don't understand how nextLine() works for all the threads I searched, but not for me.