[英]Scanner variable cannot be resolved
In my program, the user will be asked to input 3 integers.在我的程序中,将要求用户输入 3 个整数。 The integers will then be read using the
Scanner
class and listed back to the user.然后将使用
Scanner
类读取整数并返回给用户。
This is my code:这是我的代码:
import java.util.Scanner;
public class Echoer
{
public static void main(String[] args)
{
/* The Data Below Will Read The Numbers Input Into The Prompt*/
Scanner input = new Scanner(System.in);
System.out.println("Please Enter Three Integers: ");
int number;
number = input.nextInt();
Scan.close();
System.out.println("Thanks. The Numbers You Entered Are: " + number);
}
}
This is the error it returns:这是它返回的错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Scan cannot be resolved
Why does it return this error?为什么会返回这个错误? How can I fix this issue?
我该如何解决这个问题?
In your code, you never defined what Scan
was.在您的代码中,您从未定义过
Scan
是什么。 Use input.close()
rather than Scan.close()
.使用
input.close()
而不是Scan.close()
。
Scan cannot be resolved
扫描无法解析
means that you never defined Scan
.意味着您从未定义过
Scan
。 This is because you said Scan.close()
.这是因为您说的是
Scan.close()
。 You need to change it to input.close()
because input
is the name of the instance of the Scanner
class.您需要将其更改为
input.close()
因为input
是Scanner
类的实例的名称。
As others pointed out, you have to close input
instead of Scan
as shown below.正如其他人指出的那样,您必须关闭
input
而不是Scan
,如下所示。
import java.util.Scanner;
public class Echoer
{
public static void main(String[] args)
{
/* The Data Below Will Read The Numbers Input Into The Prompt*/
Scanner input = new Scanner(System.in);
System.out.println("Please Enter Three Integers: ");
int number;
number = input.nextInt();
input.close();
System.out.println("Thanks. The Numbers You Entered Are: "+number);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.