Creating an instance of the Scanner class
Your textbook may say to use the Scanner.create() method to create an instance of the Scanner class. This is no longer the way to do it. You should create an instance of the Scanner class in the same way you would create an instance of any other class, by using a constructor.
Incorrect:
Scanner myScanner = Scanner.create(System.in);
Correct:
Scanner myScanner = new Scanner(System.in);
Example:
import java.util.*;
/**
* A simple example of using the Scanner class.
*/
class EchoYourInfo
{
/**
* Echos the information you enter.
*/
public static void main(String[] args)
{
String firstName;
Scanner myScanner = new Scanner(System.in);
System.out.println("Enter your first name:");
firstName = myScanner.next();
System.out.println("Hi " + firstName);
}
}
- CS Mini Courses
- go.carleton.edu/lynda
- Installing Python On Your Home Computer
- PIL (Python Imaging Library) for Python 2.x
- Installing Java on your home computer
- Setting your Java CLASSPATH variable
- Java Documentation
- Scanner class
- TeX and LaTeX
- Running programs in the background
- Compiling in Linux
- Beep Program
- Makefiles
- Keyboard Interrupts
- Installing Cygwin







