Getting Input with the Scanner Class - Java Language Basics

Java examples for Language Basics:Console

Description

Getting Input with the Scanner Class

Demo Code

import java.util.Scanner;

public class ScannerApp
{
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args){
    System.out.print("Enter an integer: ");
    int x = sc.nextInt();
    System.out.println("You entered " + x + ".");
  }/*from w w  w. jav  a  2 s .  com*/
}

Related Tutorials