2017-11-17 324 views
0

我試圖任何人都可以告訴我Java組合類的導入語句嗎?

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 
+1

您是否已將該包添加到項目中(「Combinations」不是Java類,而是通過Apache Project庫添加的)?你在用什麼IDE? – AntonH

+0

軟件包開始時不應該有'java.'。儘管如此,您應該將導入保留到IDE中。 – bcsb1001

+2

拋棄'java.lang'位。 –

回答

0

你可以從你的import語句

java.lang.org.apache.commons.math3.util.Combinations; 

看是不是在覈心Java/JEE包,而指第三方包庫。因此您需要下載該軟件包並將其放入您的類路徑或項目lib目錄中,或使用IDE或編譯命令將該軟件包指向系統中的某個位置。然而,現在開發人員正在使用諸如maven或gradle等各種構建工具來管理這些項目依賴性開銷。

相關問題