Java has one more way for reading data from system console. Scanner was introduced in Java 1.5. Scanner class allows to read data from system console. Here I want to show example about it.
Example reads String and int values and then prints them:
import java.util.Scanner;public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); System.out.print("Username:"); String username = scanner.nextLine(); System.out.print("Number:"); int number = scanner.nextInt(); System.out.println("Username is:" + username); System.out.println("Number is:" + number); }}
Download code from this post.
Want to have latest information from this site? Subscribe to our feed.
No related posts.

Recent Comments