已经在把外部库导入java文件中,但是测试结果时能报错

 金针菇滚滚夹着五根水葱 发布于 2022-10-25 07:52

下面是我的代码,其中需要的外部库InStdOutStdIn我已经导入

import java.util.Arrays;

import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

public class BinarySearch {
     /**
      * This class should not be instantiated.
      */
    private BinarySearch() {}
    
    /**
     * Returns the index of the specified key in the specified array
     * @param a the array of integers,must be sorted in ascending order
     * @param key the search key
     * @return index of key in array {@code a} if present;{@code -1} otherwise
     */
    public static int indexOf(int[] a,int key){
        int lo = 0;
        int hi = a.length - 1;
        while(lo < hi){
            //key is in a[li..hi] or not present
            int mid = lo +(hi-lo)/2;
            if (key < a[mid]) hi = mid -1;
            else if (key > a[mid]) lo = mid + 1;
            else return mid;
        }
        return -1;
    }
    public static int rank(int key ,int a[]){
        return indexOf(a, key);
    }
    public static void main(String[] args){
        In in =new In(args[0]);
        int[] whitelist = in.readAllInts();
        
        Arrays.sort(whitelist);
        
        while(!StdIn.isEmpty()){
            int key = StdIn.readInt();
            if(BinarySearch.indexOf(whitelist, key)==-1){
                StdOut.println(key);
            }
        }
    }
}

测试结果:
*Exception in thread "main" java.lang.IllegalArgumentException: Could not open 8907

at edu.princeton.cs.algs4.In.(In.java:194)
at BinarySearch.main(BinarySearch.java:35)

Caused by: java.net.MalformedURLException: no protocol: 8907

at java.net.URL.(URL.java:585)
at java.net.URL.(URL.java:482)
at java.net.URL.(URL.java:431)
at edu.princeton.cs.algs4.In.(In.java:180)
... 1 more*
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有