Java Language Reading system input using Scanner


Example

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