Monday, July 28, 2008

ScannerApp.java

// File : ScannerApp.java
// Purpose: Write to and read from the console.

import java.util.*; //Note 1

public class ScannerApp {

  public static void main(String[] args) {
  //... Initialization
  String name; // Declare a variable to hold the name.
  Scanner in = new Scanner(System.in);

  //... Prompt and read input.
  System.out.println("What's your name?");
  name = in.nextLine(); // Read one line from the console.
  in.close(); //Note 2

  //... Display output
  System.out.println("Take me to your leader, " + name);
  }
}

No comments: