[CSC 204] Example of how to use the Scanner Class
Andrew J. Pounds
pounds_aj at mercer.edu
Tue Feb 1 08:21:27 EST 2011
It has come to my attention that several of you had some difficulties
using the Scanner class to take user input for your first programming
assignment. I am including a small "example" that should help you. If
you did not prompt for input in your Forecast.java program, then please
fix it and resubmit it.
import java.util.Scanner;
public class ScannerExample{
// This is an example of how to input a double using the Scanner class
public static void main(String argv[]){
Scanner input = new Scanner(System.in);
System.out.print("Enter x1: ");
double x1 = input.nextDouble(); // Get grade
System.out.println("You entered " + x1);
}
}
--
Andrew J. Pounds, Ph.D. (pounds at theochem.mercer.edu)
Associate Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
More information about the csc204
mailing list