0

我对 Java 编程非常陌生,我正在尝试将 jar 添加到类路径中,如下所示:

javac -classpath ~/Downloads/algs4.jar. ThreeSum.java 

但我仍然遇到以下异常:

ThreeSum.java:38: error: cannot find symbol
                        StdOut.println(a[i] + " " + a[j] + " " + a[k]);
                        ^
  symbol:   variable StdOut
  location: class ThreeSum
ThreeSum.java:62: error: cannot find symbol
        int[] a = In.readInts(args[0]);
                  ^
  symbol:   variable In
  location: class ThreeSum
ThreeSum.java:64: error: cannot find symbol
        Stopwatch timer = new Stopwatch();
        ^
  symbol:   class Stopwatch
  location: class ThreeSum
ThreeSum.java:64: error: cannot find symbol
        Stopwatch timer = new Stopwatch();
                              ^
  symbol:   class Stopwatch
  location: class ThreeSum
ThreeSum.java:66: error: cannot find symbol
        StdOut.println("elapsed time = " + timer.elapsedTime());
        ^
  symbol:   variable StdOut
  location: class ThreeSum
ThreeSum.java:67: error: cannot find symbol
        StdOut.println(cnt);
        ^
  symbol:   variable StdOut
  location: class ThreeSum
6 errors

我正在尝试这里的程序

4

2 回答 2

2

看起来你也需要下载这个 JAR:http: //introcs.cs.princeton.edu/java/stdlib/

它们没有包结构,因此将所有内容解压缩到同一目录中:

jar xvf stdlib.jar
jar xvf algs4.jar

然后编译它:

javac -classpath . ThreeSum.java
于 2013-03-29T04:33:22.107 回答
1

您可能希望该类~/Downloads/algs4.jar.路径~/Downloads/algs4.jar:.位于 Linux 或Windows 上~/Downloads/algs4.jar;.

于 2013-03-29T04:18:02.490 回答