From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Get string values from user input

Get string values from user input - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Get string values from user input

- [Instructor] In a command line application you can get string based input using a class named Scanner. The first step is to create an instance of that class. In this beginning application I'll create a variable that I'll name scanner, and I'll instantiate it with new scanner. And then I need to pass in a location from which the data is going to come. And I'll pass in the expression, system dot in. Now notice I'm getting a warning that this symbol scanner isn't recognized, so I'll place the cursor inside the class name and then hold down the Alt or option key and press enter or return, and I'll choose Import Class. And that will create the import statement that's required at the top of the file. Now I can receive input. Before I receive the input I want to tell the user what I'm expecting. So I'm going to use system dot out but this time instead of println I'll just use a method named print and that'll output a string…

Contents