how to get string input line in java

www.lautt‮.iru‬com
how to get string input line in java

To get a string input line in Java, you can use the Scanner class to read the input from the command line. The Scanner class provides a method called nextLine() that reads a line of input as a string.

Here's an example of how you can get a string input line in Java:

import java.util.Scanner;

// ...

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a line of text: ");
String line = scanner.nextLine();

In this example, the scanner object is a Scanner instance that reads the input from the command line, and the nextLine() method is used to read and return the input as a string. The line variable holds the input string.

You can use the Scanner class to read input from other sources as well, such as a file or a string.

Created Time:2017-11-01 20:42:55  Author:lautturi