Reputation: 131
This is my Code
public class Workshop3
{
public static void main (String [] args)
{
System.out.println ("please enter radius of circle");
double radius;
Scanner keyboard = new Scanner (System.in);
keyboard.nextDouble (radius);
}
}
The error I recieve is
cannot find symbol - class scanner
on the line
Scanner keyboard = new Scanner (System.in);
Upvotes: 13
Views: 128929
Reputation: 11
Please add the following line on top of your code
import java.util.*;
This should resolve the issue
Upvotes: 1
Reputation: 117597
You have to import java.util.Scanner
at first line in the code.
import java.util.Scanner;
Upvotes: 6
Reputation: 177
Add import java.util.Scanner;
at the very top of your code. Worked for me.
Upvotes: 0
Reputation: 11
sometimes this can occur during when we try to print string from the user so before we print we have to use
eg: Scanner scan=new Scanner (System.in);
scan.nextLine(); // if we have output before this string from the user like integer or other dat type in the buffer there is /n (new line) which skip our string so we use this line to print our string
String s=scan.nextLine();
System.out.println(s);
Upvotes: 1
Reputation: 48596
You need to include the line import java.util.Scanner;
in your source file somewhere, preferably at the top.
Upvotes: 5
Reputation: 11
You can resolve this error by importing the java.util.*
package - you can do this by adding following line of code to top of your program (with your other import
statements):
import java.util.*;
Upvotes: 1
Reputation: 3742
As the OP is a new beginner to programming, I would like to explain more.
You wil need this line on the top of your code in order to compile:
import java.util.Scanner;
This kind of import statement is very important. They tell the compile of which kind of Scanner you are about to use, because the Scanner here is undefined by anyone.
After a import statement, you can use the class Scanner directly and the compiler will know about it.
Also, you can do this without using the import statement, although I don't recommend:
java.util.Scanner scanner = new java.util.Scanner(System.in);
In this case, you just directly tell the compiler about which Scanner you mean to use.
Upvotes: 27