The Future Is Behind You

Keyboard Input

The Scanner class can be used to get input from the user at the keyboard.

import java.util.Scanner;

public class Keyboard {

  public static void main(String[] args) {
    Scanner keyboard = new Scanner(;
    System.out.print("enter a number: ");
    int num = keyboard.nextInt();
    System.out.println("You entered: " + num);

Source Code

Here's how the program runs and some sample input/output.

$ java Keyboard
enter a number: 56
You entered: 56

a = b = c

Twitter: @kegg