Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"cannot find symbol - class Scanner" error

Tags:

java

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);
like image 818
James Blundell Avatar asked May 11 '11 03:05

James Blundell


2 Answers

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.

like image 157
lamwaiman1988 Avatar answered Sep 17 '22 11:09

lamwaiman1988


Add import java.util.Scanner; at the very top of your code. Worked for me.

like image 33
Audrey Mengue Avatar answered Sep 17 '22 11:09

Audrey Mengue