用Scanner类读取用户输入Java
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用Scanner类读取用户输入Java相关的知识,希望对你有一定的参考价值。
This snippet will allow you to read user's input when they write in the console. This method uses the Scanner class, which is my favorite way of doing instead of using the Buffered Reader, with the Scanner, you can also read from a file.
import java.util.Scanner; public class ReadUserInput { //to read from the keyboard(System.in) name = sc.nextLine(); //Sets name equal to user's input //if you just call the "next" method, the Scanner will read up to the first space. } }
以上是关于用Scanner类读取用户输入Java的主要内容,如果未能解决你的问题,请参考以下文章