本文介绍了编译错误:找不到符号:In,StdIn和StdOut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码来自

import java.util.Arrays;

public class BinarySearch {

    // precondition: array a[] is sorted
    public static int rank(int key, int[] a) {
        int lo = 0;
        int hi = a.length - 1;
        while (lo <= hi) {
            // Key is in a[lo..hi] or not present.
            int mid = lo + (hi - lo) / 2;
            if      (key < a[mid]) hi = mid - 1;
            else if (key > a[mid]) lo = mid + 1;
            else return mid;
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] whitelist = In.readInts(args[0]);

        Arrays.sort(whitelist);

        // read key; print if not in whitelist
        while (!StdIn.isEmpty()) {
            int key = StdIn.readInt();
            if (rank(key, whitelist) == -1)
                StdOut.println(key);
        }
    }
}

我收到此错误

$ javac BinarySearch.java
BinarySearch.java:44: cannot find symbol
symbol  : variable In
location: class BinarySearch
        int[] whitelist = In.readInts(args[0]);
                          ^
BinarySearch.java:49: cannot find symbol
symbol  : variable StdIn
location: class BinarySearch
        while (!StdIn.isEmpty()) {
                ^
BinarySearch.java:50: cannot find symbol
symbol  : variable StdIn
location: class BinarySearch
            int key = StdIn.readInt();
                      ^
BinarySearch.java:52: cannot find symbol
symbol  : variable StdOut
location: class BinarySearch
                StdOut.println(key);
                ^
4 errors


推荐答案

StdIn StdOut 中不属于标准的Java库。他们为普林斯顿大学课程提供支持课程。

Classes StdIn, StdOut and In aren't part of the standard Java libraries. They're support classes provided to go along with the Princeton course.

来自页面:

...

和是面向对象的版本,支持多个输入和输出流,包括从文件或URL读取并写入文件。

In.java and Out.java are object-oriented versions that support multiple input and output streams, including reading from a file or URL and writing to a file.

因此,如果您想按原样使用二进制搜索代码,则需要下载这些文件。

So if you want to use the binary search code as-is, you'll need to download those files.

这篇关于编译错误:找不到符号:In,StdIn和StdOut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:27