/ Published in: 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.
Expand |
Embed | Plain Text
import java.util.Scanner; public class ReadUserInput { //to read from the keyboard(System.in) String name; // The variable which is going to store the user's input 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. } }
You need to login to post a comment.
