Reading system input using Scanner

suggest change
Scanner scanner = new Scanner(System.in); //Scanner obj to read System input
String inputTaken = new String();
while (true) {
    String input = scanner.nextLine(); // reading one line of input
    if (input.matches("\\s+"))         // if it matches spaces/tabs, stop reading
        break;
    inputTaken += input + " ";
}
System.out.println(inputTaken);

The scanner object is initialized to read input from keyboard. So for the below input from keyboar, it’ll produce the output as Reading from keyboard

Reading
from
keyboard
  //space

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents