我正在使用 Java 处理一些简单的数据结构,我正在使用普林斯顿的库来实现数据结构,但是 VS Code 无法选择导入语句下使用的文件,但如果我从终端。
这是我的 Java 代码,带有描述情况的注释:
//these imports work fine
import java.util.Iterator;
import java.util.NoSuchElementException;
//this is available in my local directory
//VS code is unable to resolve these imports, however it works fine while using integrated terminal
import edu.princeton.cs.algs4.Bag;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;
public class Stats {
public static void main(String[] args) {
// read in numbers
Bag<Double> numbers = new Bag<Double>();
int i = 0;
while (i < args.length) {
numbers.add(Double.parseDouble(args[i]));
i++;
}
int n = numbers.size();
// compute sample mean
double sum = 0.0;
for (double x : numbers)
sum += x;
double mean = sum / n;
// compute sample standard deviation
sum = 0.0;
for (double x : numbers) {
sum += (x - mean) * (x - mean);
}
double stddev = Math.sqrt(sum / (n - 1));
StdOut.printf("Mean: %.2f\n", mean);
StdOut.printf("Std dev: %.2f\n", stddev);
}
}
这是我在 VS Code 构建错误中收到的信息:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
StdOut cannot be resolved
StdOut cannot be resolved
有人可以帮我吗?我正在使用 Microsoft 的 Java 扩展包
摇曳的蔷薇
30秒到达战场
相关分类