Using Scanner for Input in Java


Scanner is a simple text scanner which can parse primitive types and strings using regular expressions.

Source Code

import java.util.Scanner;

public class ScannerExample {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter your name: ");
        String name = scanner.nextLine();
        System.out.println("Hello, " + name);
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments