【问题标题】:My scanner keeps getting the error "cannot find symbol"我的扫描仪不断收到错误“找不到符号”
【发布时间】:2015-03-25 16:29:55
【问题描述】:

我遇到了一个问题,因为当我尝试编译我的代码时,它说找不到该扫描仪作为符号。

我能做些什么来解决它?

public class Unit10
{
    public static void main( String[] args )
    {
    scanner input =  new scanner(System.in);
        int numEmployees;
        System.out.println( "How many employees do you wish to enter?" );
        numEmployees = input.nextInt();
        Employee[] employeeArray = new Employee[numEmployees]; 
        for ( int i = 0; i < numEmployees; i++ ) 
        {
            Employee e1 = new Employee();  
            Name first = new Name();
            Name last = new Name();
            System.out.println( "Enter the first name of the employee" );
            e1.setFirstName( input.nextLine() );
            System.out.println( "Enter the last name of the employee" );
            e1.setLastName( input.nextLine() );
        }
    }
}

【问题讨论】:

    标签: java int java.util.scanner


    【解决方案1】:

    Scanner是一个类,库中的每个类都以大写字母开头:

    Scanner input = new Scanner(System.in);
    

    【讨论】:

    • 当我改变这两个扫描仪的情况时,它仍然说“找不到符号”
    【解决方案2】:

    您是否在程序开始时导入了 java.util.scanner?

    另外,我认为是“扫描仪”而不是“扫描仪”

    【讨论】:

      【解决方案3】:

      使用这个导入:

      import java.util.Scanner;
      

      【讨论】:

      • 现在我已经添加了 import java.util.Scanner;意思是 import 是表达式的非法开始,而 util.Scanner 不是语句
      • import 语句必须在类定义之前。
      • 正如 npostavs 所说,它需要在类定义之前。换句话说,在文件的顶部,高于所有其他代码。
      猜你喜欢
      • 2015-06-02
      • 2014-12-28
      • 2015-11-27
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多