Getting input

Report a typo

The Scanner class is widely used to parse text to strings, and it is by far the simplest way to get input in Java.

In this task, you simply need to implement the getString() method of InputReader to read a whole line of input using the nextLine() method of Scannerand return it as String. The trick is to use the Scanner class without the import statement. The application will receive a string from the getString() method and use it like so:

System.out.println("The input string: " + InputReader.getString());

Only implement the getString() and make sure to return a string without changes. Don't create the main method.

Write a program in Java 17
class InputReader {
public static String getString() {
// write your code here
}
}
___

Create a free account to access the full topic