Home - Programming - Java- User Input
User Input
/** * Application: User Input * Author: Brian SonniE * 19/10/09 * www.fluidcoding.com */ // An import statement is needed to access the Scanner class. // This will be used to accept user input. import java.util.Scanner; public class UserInput { public static void main(String[] args) { // Create a scanner object Scanner keyboard = new Scanner(System.in); // Ask the user his/her name System.out.println("Enter Your Name: "); // Get the user input as a string using the next method. String yourName = keyboard.next(); // Print the welcome message. System.out.println("Hello " + yourName + ", Welcome To FluidCoding."); } }
Output
Enter Your Name:
Sonnie [User Input]
Hello Sonnie, Welcome To FluidCoding.
Sonnie [User Input]
Hello Sonnie, Welcome To FluidCoding.