Since this is a long time, and people continue to suggest using Scanner#nextLine() , there is another chance that Scanner can accept spaces included in input.
Scanner class
The scanner splits its input into tokens using the delimiter pattern, which by default matches a space.
You can use Scanner#useDelimiter() to change the Scanner separator to another template, such as line feed or something else.
Scanner in = new Scanner(System.in); in.useDelimiter("\n"); // use LF as the delimiter String question; System.out.println("Please input question:"); question = in.next(); // TODO do something with your input such as removing spaces... if (question.equalsIgnoreCase("howdoyoulikeschool?") ) /* it seems strings do not allow for spaces */ System.out.println("CLOSED!!"); else System.out.println("Que?");
source share