0
import java.lang.org.apache.commons.math3.util.Combinations;
導入組合,但我不斷收到錯誤,當我在源代碼中使用的組合。
import java.util.*;
import java.org.apache.commons.math3.util.Combinations;
public class PowerSet{ //gets power set for a set containing first n integers
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = Integer.parseInt(args[0]);
for(int i=0; i<=n; i++){
Combinations c = new Combinations(n,i);
Iterator iter = c.iterator();
while(iter.hasNext()){
int[] iarr = (int[])iter.next();
System.out.print("{" + iarr[0]);
for(int a=1; a<iarr.length; a++){
System.out.println(", " + iarr[a]);
}
System.out.print("}, ");
}
}
}
}
而我明白的錯誤表明該類不存在。我是否得到錯誤的層次結構或我應該導入類的方式是錯誤的?
package java.org.apache.commons.math3.util does not exist
import java.org.apache.commons.math3.util.Combinations;
^
PowerSet.java:11: error: cannot find symbol
Combinations c = new Combinations(n,i);
^
symbol: class Combinations
location: class PowerSet
您是否已將該包添加到項目中(「Combinations」不是Java類,而是通過Apache Project庫添加的)?你在用什麼IDE? – AntonH
軟件包開始時不應該有'java.'。儘管如此,您應該將導入保留到IDE中。 – bcsb1001
拋棄'java.lang'位。 –