我写我的代码,我想在返回多个值:如何在java中返回多个值?
public int[] getResult(){
return geneticAlgorithm(cost,profit,gens,turns,cmax);
,但是当我用这个告诉我eror:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: knapsacproject.algorithm.geneticAlgorithm([I[IIII)[I
at knapsacproject.algorithm.geneticAlgorithm(Native Method)
at knapsacproject.algorithm.getResult(algorithm.java:39)
我的代码:
package knapsacproject;
public class algorithm {
public native int [] geneticAlgorithm(int[] cost, int[] profit,int cmax, int gens, int turns);
static {
try {
System.load("C:/Users/Desktop/dp/KnapSacProject/src/knapsacproject/helo.dll");
System.out.println("loaded successfully");
} catch (Exception e){
e.printStackTrace();
}
}
protected int[] cost, profit, result;
protected int gens, turns, cmax;
public algorithm(int[] cost,int[] profit, int gens ,int turns , int cmax) {
this.cost=cost;
this.profit=profit;
this.gens=gens;
this.turns=turns;
this.cmax=cmax;
}
public int[] getResult(){
return geneticAlgorithm(cost,profit,gens,turns,cmax);
}
public static void main (String[] args) {
}
}
那么如何我返回多个值或如何解决这个问题?
那......甚至没有像Java代码,给我。我认为你是在混合类和函数,Java保持两个不同的域......像this.cost这样的行将引用自己的类。如果你想返回多个值,您可能需要返回具有这些值的字段类,或建立他们的数组(如果他们是同一类型的。)的 –
可能的复制[如何返回从多个对象Java方法?(http://stackoverflow.com/questions/457629/how-to-return-multiple-objects-from-a-java-method) –
如果你希望人们看你的代码,至少使一些努力以可读的方式对其进行格式化。 –