我正在尝试编译以下代码:
package week1;
public class ThreeSum {
public static int count(int[] a) {
// count triples that sum to 0
int count = 0;
for (int i = 0; i<a.length; i++) {
for (int j = i+1; j < a.length; j++) {
for (int k = j+1; k < a.length; k++) {
if (a[i] + a[j] + a[k] == 0) {
count++;
}
}
}
}
return count;
}
public static void main(String[] args) {
int[] a = In.readInts(args[0]);
StdOut.println(count(a));
}
}
此代码位于 week1 文件夹中的 ThreeSum.java 文件中。“In”和“StdOut”两个类都在./lib
文件夹中的包 stdlib.jar 中。我一直使用 IDE,现在决定使用命令行。所以在我的
javac -cp .:lib/stdlib.jar week1/ThreeSum.java
和其他类路径参数变体它返回错误:
week1\ThreeSum.java:20: error: cannot find symbol
int[] a = In.readInts(args[0]);
^
symbol: variable In
location: class ThreeSum
week1\ThreeSum.java:21: error: cannot find symbol
StdOut.println(count(a));
^
symbol: variable StdOut
location: class ThreeSum
在我的情况下,正确的 -cp 选项应该是什么样子?