Need help with basic Java?

Need help with basic Java?
For school I started with a jumbled up mess of code and was told to fix it. I have combed the code and fixed mistakes all over. Now I am stuck on one little part. It is a code to find the average of 3 numbers input by the user. I figured out it was missing something to define the keyboard. So, I added this:

Scanner keyboard = new Scanner(System.in);

Now it says “Cannot find symbol. Symbol: class Scanner”

I am not sure what to do now. Thank you in advance for the help. Here is the code…

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int firstNumber, secondNumber, thirdNumber;

System.out.println(“Enter first number: “); //The user must input the first number here
firstNumber=keyboard.nextInt();
//this varriable is set by the user
System.out.println(“Enter second number: “);
secondNumber=keyboard.nextInt();
System.out.println(“Enter third number: “);
thirdNumber=keyboard.nextInt();
//The three numbers input by the user

//The output is the average of the three numbers input by the user
System.out.println(“The average of the numbers is ” +
((firstNumber + secondNumber + thirdNumber)/3));

}

}
Ok, that helped, but still did not fix the problems

Best answer:

You need to import java.util.Scanner first!!! =)

put it in the header of the program:

import java.util.scanner;

Tags: , , ,

Under Forum

1 Comment for Need help with basic Java?

  • 1. cold watermelon  |  December 19th, 2007 at 9:00 am

    you can try to import java.util.Scanner;

Leave a Comment for Need help with basic Java?

Required

Required, hidden

Trackback this post  |  Subscribe to the comments via RSS Feed


Forum