编译错误:找不到符号:In,StdIn和StdOut [英] compile error: cannot find symbol: In, StdIn and StdOut
问题描述
代码来自
http://algs4.cs.princeton.edu/11model算法教科书的/BinarySearch.java.html 。
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.
来自 1.1编程模型页面:
标准输入和标准输出。
StdIn.java
和StdOut.java
是用于从标准输入读取数字和文本并将数字和文本打印到标准输出的库。我们的版本比相应的Java版本具有更简单的界面(并提供了一些技术改进)。
Standard input and standard output.
StdIn.java
andStdOut.java
are libraries for reading in numbers and text from standard input and printing out numbers and text to standard output. Our versions have a simpler interface than the corresponding Java ones (and provide a few tecnical improvements).
...
In.java
和 Out.java
是面向对象的版本,支持多个输入和输出流,包括从文件或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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!