算法第四版(Algs4) 在Eclipse中调用Algs4.jar

Algs4.jar

1.下载地址(页面往下拉一拉,在末尾): https://algs4.cs.princeton.edu/windows/

2.添加步骤: Properties -> Java Build Path -> Libraries -> Add Extenernal JARs

 

测试用例:TestAlgs4.java

1.注:在Algs4.jar包下有默认包(default package)下也有相同测试代码,可直接运行。

代码如下:

import edu.princeton.cs.algs4.StdDraw;

public class TestAlgs4 {
    public static void main(String[] args) {
        StdDraw.setScale(-1, 1);
        StdDraw.clear(StdDraw.BLACK);
        
        StdDraw.setPenColor(StdDraw.WHITE);
        StdDraw.square(0, 0, 1);
        
        // write some text
        StdDraw.setPenColor(StdDraw.WHITE);
        StdDraw.text(0, +0.95, "Hello, world! This is a test Java program.");
        // StdDraw.text(0, -0.95, "Close this window to finish the installation.");
        
        // draw the bullseye
        StdDraw.setPenColor(StdDraw.BOOK_BLUE);
        StdDraw.filledCircle(0, 0, 0.9);
        StdDraw.setPenColor(StdDraw.BLACK);
        StdDraw.filledCircle(0, 0, 0.8);
        StdDraw.setPenColor(StdDraw.BOOK_BLUE);
        StdDraw.filledCircle(0, 0, 0.7);
        StdDraw.setPenColor(StdDraw.BLACK);
        StdDraw.filledCircle(0, 0, 0.6);

        // draw a picture of the textbook        
        StdDraw.picture(0, 0, "cover.jpg", 0.65, 0.80);
    }
}

2.运行结果

算法第四版(Algs4) 在Eclipse中调用Algs4.jar_第1张图片

 

新手一枚,欢迎大家提出问题和希望和大家多多讨论交流~~

 

你可能感兴趣的:(Algs4学习)