Question:
I'm looking for a simple example of the Scanner class.
Code:
import java.util.Scanner; public class ReadInput { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter string: "); String str = sc.nextLine(); System.out.println("Your string: " + str); } }
Output:
$ java ReadInput Enter string: Hello There Your string: Hello There