Java 程序不喜欢“扫描仪”这个词

发布于 2024-10-04 22:08:51 字数 884 浏览 0 评论 0原文

import java.lang.*;
import java.util.*;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.IOException;

public class Test
{
  public static void main(String[] args) throws IOException
  {
    Scanner infile = new Scanner(new FileReader("historyGrades.txt"));
    boolean[] correctAnswers = new boolean[20];
    infile.close();
  }
}

由于某种原因我收到这些错误:

C:\Users\Rawr\Documents\Test.java:11: cannot resolve symbol
symbol  : class Scanner 
location: class Test
    Scanner infile = new Scanner(new FileReader("historyGrades.txt"));
    ^
C:\Users\Rawr\Documents\Test.java:11: cannot resolve symbol
symbol  : class Scanner 
location: class Test
    Scanner infile = new Scanner(new FileReader("historyGrades.txt"));
                         ^
2 errors

Tool completed with exit code 1

我不知道发生了什么。 感谢帮助,谢谢。

import java.lang.*;
import java.util.*;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.IOException;

public class Test
{
  public static void main(String[] args) throws IOException
  {
    Scanner infile = new Scanner(new FileReader("historyGrades.txt"));
    boolean[] correctAnswers = new boolean[20];
    infile.close();
  }
}

I'm getting these errors for some reason:

C:\Users\Rawr\Documents\Test.java:11: cannot resolve symbol
symbol  : class Scanner 
location: class Test
    Scanner infile = new Scanner(new FileReader("historyGrades.txt"));
    ^
C:\Users\Rawr\Documents\Test.java:11: cannot resolve symbol
symbol  : class Scanner 
location: class Test
    Scanner infile = new Scanner(new FileReader("historyGrades.txt"));
                         ^
2 errors

Tool completed with exit code 1

I have no idea what's going on.
Help is appreciated, Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不必在意 2024-10-11 22:08:51

您使用的是哪个版本的 Java? Scanner 是在 1.5 中添加的。

Which version of Java are you using? Scanner was added in 1.5.

梦境 2024-10-11 22:08:51

在命令提示符(终端)上运行以下命令;

java -version

如果返回的版本号小于1.5,那么您必须下载新版本的Java。扫描仪类在之前的版本中不可用。从这里下载新版本的SDK;

Java SE 下载

设置新版本后对于 Java,请在源文件中添加以下导入语句;

import java.util.Scanner;

现在编译你的源代码。现在应该像 F16 一样了。但如有任何问题,请随时询问。

Run the following command on command prompt (terminal);

java -version

If the returned version number is less than 1.5 then you have to download the new version of Java. Scanner class is not available in prior versions. Download the new version of SDK from here;

Java SE Downloads

After setting up the new version of Java, add the following import statement in your source file;

import java.util.Scanner;

Now compile your source. It should go like a F16 now. But feel free to ask in case of any problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文