Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.util.scanner

807598Sep 5 2006 — edited Sep 12 2006
I'm on Ubuntu 6.06 Dapper Drake (Linux), and when I try to compile this program, I get an error message. I'm pretty sure I don't have the ultility in the right place on my system, but I've exhausted my resources and I can find any sort of package or install file. This is an example program from my class, and It still doesn't compile correctly.

Here's the class:

import java.util.Scanner;

public class GasMileage
{
//-----------------------------------------------------------------
// Calculates fuel efficiency based on values entered by the
// user.
//-----------------------------------------------------------------
public static void main (String[] args)
{
int miles;
double gallons, mpg;

Scanner scan = new Scanner (System.in);

System.out.print ("Enter the number of miles: ");
miles = scan.nextInt();

System.out.print ("Enter the gallons of fuel used: ");
gallons = scan.nextDouble();

mpg = miles / gallons;

System.out.println ("Miles Per Gallon: " + mpg);
}
}

and my error messages:

pietre@pietre-laptop:~/Desktop/CSCI 141: Intro to Comp. Sci$ javac GasMileage.java
----------
1. ERROR in GasMileage.java
(at line 7)
import java.util.Scanner;
^^^^^^^^^^^^^^^^^
The import java.util.Scanner cannot be resolved
----------
2. ERROR in GasMileage.java
(at line 20)
Scanner scan = new Scanner (System.in);
^^^^^^^
Scanner cannot be resolved to a type
----------
3. ERROR in GasMileage.java
(at line 20)
Scanner scan = new Scanner (System.in);
^^^^^^^
Scanner cannot be resolved to a type
----------
3 problems (3 errors)

A little help would be great.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2006
Added on Sep 5 2006
17 comments
610 views