Input and Output
Learn how Java programs can receive information from users using Scanner.
Java Code
Study the example and understand what each part does.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = input.nextLine();
System.out.println("Welcome " + name);
}
}
Java code normally runs using the Java Development Kit on a computer, Android Studio or another Java development environment. This course page presents the code examples without pretending that the browser is running Java directly.
Expected Output / Result
Run this Java example in a Java development environment to see the result.
Finished this lesson?
Mark it complete to update your course progress.