java StdRandom, StdOut, Insertion 无法解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12770063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:08:25  来源:igfitidea点击:

StdRandom, StdOut, Insertion cannot be resolved

javasortinginput

提问by Aleksei Chepovoi

This code should implement sorting.
I have 3 errors:
"StdRandom cannot be resolved",
"StdOut cannot be resolved",
"Insertion cannot be resolved".
May be there are some libraries to import?

这段代码应该实现排序。
我有 3 个错误:
“无法解析
StdRandom ”、“无法解析 StdOut ”、“无法解析
插入”。
可能有一些库要导入?

public class randomDoubles 
{
public static void main(String[] args)
{

    int N = Integer.parseInt(args[0]);
    Double[] a = new Double[N];
    for(int i = 0; i < N; i++)
        a[i] = StdRandom.uniform(); // error: StdRandom cannot be resolved
    Insertion.sort(a);                  // error: Insertion cannot be resolved
    for (int i = 0; i < N; i++)
        StdOut.println(a[i]);       // error: StdOut cannot be resolved
}
}

回答by Don Roby

You're definitely missing some imports of non-standard libraries here. If you want to compile and use this code as it is, you should ask your professor where to find the libraries and how to import them.

您肯定在这里缺少一些非标准库的导入。如果您想按原样编译和使用此代码,您应该询问您的教授在哪里可以找到这些库以及如何导入它们。

But if you just want an example of doing approximately what's shown here with standard java libraries, the following might suffice:

但是,如果您只是想要一个使用标准 Java 库执行此处显示的大致内容的示例,则以下内容可能就足够了:

import java.util.Arrays;
import java.util.Random;

public class RandomDoubles {

    public static void main(String[] args)
    {

        int N = Integer.parseInt(args[0]);
        Double[] a = new Double[N];
        Random rand = new Random();
        for(int i = 0; i < N; i++)
            a[i] = rand.nextDouble();
        Arrays.sort(a);
        for (int i = 0; i < N; i++)
            System.out.println(a[i]);
    }

}

回答by Jams Brown

you can download jar from site below http://algs4.cs.princeton.edu/code/, and import it to your project

您可以从http://algs4.cs.princeton.edu/code/下面的站点下载 jar ,并将其导入到您的项目中

回答by u6949852

The link offered by others didn't handle idea. If you are idea(jetbrains intellij idea) user, you also need go to File->Project Structure->Libraries and add algs4.jar

其他人提供的链接没有处理想法。如果你是idea(jetbrains intellij idea)用户,你还需要去文件->项目结构->库并添加algs4.jar

回答by christian Martin

I had a similar issue years ago when I took the same class, the issue here is that StdRabdomand StdOutare all third party libraries written by the course authors. The only way to solve this issue is by installing libraries to your local machine like rv1822 mentioned. The installation instructions are also included in the provided link.

我类似的问题,年前就有,当我把同一类,这里的问题是,StdRabdomStdOut是由课程作者所写的所有第三方库。解决此问题的唯一方法是将库安装到您的本地机器上,如提到的 rv1822。安装说明也包含在提供的链接中。