Question:

Character whitespace(spacing) in java

by  |  earlier

0 LIKES UnLike

how do make a scanner recognize a whitespace(spacing) so when the user enters "hello how are you" java does not throw an exception

 Tags:

   Report

1 ANSWERS


  1. Scanner uses the whitespace as default delimiter to separate inputs. It has a useDelimiter()-Method to change this. It uses Regular Expressions as delimiters, so that some characters in the String passed to the useDelimiter()-Method are interpreted as placeholders. For example, to scan a line of user input, you can use the newline-character (produced when the user presses the enter key), symbolized by the delimiter string "\\n":

    Scanner sc = new Scanner(System.in);

    sc.useDelimiter("\\n");

    String lineInput = sc.next();

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.