我有一个双数组,其中我需要使用jtextfield输入搜索第一行,以获得索引(I的位置),然后使用该索引号来标识第二行的位置,并使用第二个数组行中的变量。我用它来得到数组第二行的毛利率乘数,它基于第一行数组中的百分比利润的位置。
感谢您的帮助。我已经搜索了其他数组链接,但它们处理的是位置而不是位置的内容。
public void getMarginArray(){
double[][] margn = {{10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50},
{1.11, 1.12, 1.13, 1.15, 1.16, 1.17, 1.19, 1.20, 1.22, 1.23, 1.25, 1.26, 1.28, 1.30, 1.31, 1.33, 1.35, 1.37, 1.39, 1.41, 1.43, 1.45, 1.47, 1.49, 1.51, 1.55, 1.56, 1.59, 1.61, 1.64, 1.67, 1.70, 1.72, 1.75, 1.79, 1.82, 1.86, 1.89, 1.92, 1.96, 2.00}};
Double MARG = Double.parseDouble( jtxtfldMargin.getText());
Double MAR1;
for (int i=0; i<margn.length; i++){
if (margn[0][i] ==MARG){
Double MAR1=margn[1][i];
System.out.println(margn[0][i]);
System.out.println(margn[1][i]);
System.out.println(MAR1);
};
};
我可以通过切换到两个独立的阵列来获得所需的内容。现在,当第一个数组与文本字段匹配时,该位置将用于第二个数组以获取乘数:
public void getMarginArray(){
double[] doubleArray1 = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
double[] doubleArray2 = {1.11, 1.12, 1.13, 1.15, 1.16, 1.17, 1.19, 1.20, 1.22, 1.23, 1.25, 1.26, 1.28, 1.30, 1.31, 1.33, 1.35, 1.37, 1.39, 1.41, 1.43, 1.45, 1.47, 1.49, 1.51, 1.55, 1.56, 1.59, 1.61, 1.64, 1.67, 1.70, 1.72, 1.75, 1.79, 1.82, 1.86, 1.89, 1.92, 1.96, 2.00};
Double MARG = Double.parseDouble( jtxtfldMargin.getText());
Double margMult;
for(int i = 0; i<doubleArray1.length; i++){
for(int j = 0; j<doubleArray2.length;j++){
if(doubleArray1[i] == MARG ){
margMult = doubleArray2[i];
System.out.println(margMult);
}
}
}
}