Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
340 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...