Java ClassesLesson 42Free preview
Java User Input
This lesson is part of Java · All levels
Summary
To receive data from users, Java provides class Scanner on the java.util package. The scanner can read integers, decimals, or a single line of text from the keyboard input. Always close the Scanner object with close() after completion so that the resource does not leak.
Key points
- Make the Scanner with new Scanner(System.in) to read from the keyboard
- Read the whole number, read the decimal, read the line
- Import.Scanner must be written to recognize class Scanner
- Close the Scanner with close() after use is complete
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.