2d数组的null输出

时间:2016-02-24 20:15:55

标签: java arrays

你好@ll stackExchange社区膜我希望你很好我在这里有一个关于二维数组的小问题

public static void fit(ArrayList <features> malade,ArrayList <features> learning) {    
      int e=malade.size();
      int i=learning.size();
      Double[][] multi = new Double[i][e];                 
      for (int cont = 0; cont >= i; cont++){
           for (int compt = 0; compt >= e; compt++){
               Double Plaglu = Double.parseDouble(learning.get(cont).plaglu)-Double.parseDouble(malade.get(compt).plaglu);
               Double press = Double.parseDouble( learning.get(cont).press)-Double.parseDouble(malade.get(compt).press);
               Double Tricep = Double.parseDouble(learning.get(cont).tricpe)-Double.parseDouble(malade.get(compt).tricpe);
               Double serins = Double.parseDouble(learning.get(cont).serins)-Double.parseDouble(malade.get(compt).serins);
               Double bmi = Double.parseDouble(learning.get(cont).bmi)-Double.parseDouble(malade.get(compt).bmi);
               Double fun = Double.parseDouble(learning.get(cont).fun)-Double.parseDouble(malade.get(compt).fun);
               Double pla = Plaglu*Plaglu;
               Double pres = press*press;
               Double tri = Tricep*Tricep;
               Double serin = serins*serins;
               Double bm = bmi*bmi;
               Double finc = fun*fun;  
               Double somme = pla+pres+tri+serin+bm+finc;
               Double sol = Math.sqrt(somme);
               multi[cont][compt] = sol;
               i--;
           }
           e--; 
      }     

      /*method number one*/    
      for (Double[] row : multi) {
          Arrays.fill(row, 0);
          System.out.println(Arrays.toString(row)); 
      }               

      /*method number two*/ 
      for(int r = 0; r < learning.size(); r++)   
      {
          for(int g = 0; g < malade.size(); g++)
          {
               System.out.println(multi[r][g]);
          }   
     }     
 }

我已经尝试了两种方法来打印结果itch是多和 我得到null输出或2 ArrayLists已满 这里有任何帮助

2 个答案:

答案 0 :(得分:1)

尝试替换它:

  for (int cont = 0; cont >= i; cont++){
    for (int compt = 0; compt >= e; compt++){

使用<代替>=

  for (int cont = 0; cont < i; cont++){
       for (int compt = 0; compt < e; compt++){

答案 1 :(得分:0)

原因是np.load循环中的条件相反:

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.win32.StdCallFunctionMapper;

import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class JnaTest {


    static {
    Map options = new HashMap();
        options.
                put(
                        Library.OPTION_FUNCTION_MAPPER,
                        new StdCallFunctionMapper() {
                            HashMap<String, String> map = new HashMap() {
                                {
                                    put("testMethod", "testMethod@0");
                                }
                            };
                            @Override
                            public String getFunctionName(NativeLibrary library, Method method) {
                                String methodName = method.getName();
                                return map.get(methodName);

                            }
                        }
                );

        File LIB_FILE = new File("test.dll");
        Native.register(NativeLibrary.getInstance(LIB_FILE.getAbsolutePath(), options));

    }

    private static native int testMethod();

    public static void main(String[] args) {
        testMethod(); // call the native method in the loaded dll with the function name testMethod@0
    }


}

应替换为

for

无需for (int cont = 0; cont >= i; cont++){ for (int compt = 0; compt >= e; compt++){ for (int cont = 0; cont <= learning.size(); cont++){ for (int compt = 0; compt <= malade.size(); compt++){