gpt4 book ai didi

java - 类不读取数组

转载 作者:行者123 更新时间:2023-12-01 13:11:48 25 4
gpt4 key购买 nike

我有两个类,MainActivity 和 HjorthClass。

请注意 MainActivity 底部的 TestSeizureDetected()。其他一切都工作正常。当我运行 testValue.returnVal() 时,我只得到值 1.0。无论字符串中的数字如何,该数字都不会改变。我已经通过打印不同位置的值来验证 FinalSeizureData 的准确性。

String巨大由7681个单独的值组成,并且不包括在其中。问题出在我的 Hjorthclass 中,但我无法弄清楚它在哪里或为什么 returnVal 只返回 1.0。

*编辑:*仅显示相关代码。由于代码已被编辑并减少了大小,因此请勿指出 MainActivity 中的语法错误。谢谢。

public class MainActivity extends Activity implements LocationListener{
public double[][] finalSeizureData= new double[7681][1];

public HjorthClass testValue;


public void TestSeizureDetected()
{
String[] temp = huge.split("\\s+");
double[] convert = new double[temp.length];
for(int y = 0; y<convert.length; y++)
{
convert[y]= Double.parseDouble(temp[y]);
}
for(int i = 0; i<convert.length;i++)
{
for(int j = 0; j<1;j++)
{
finalSeizureData[i][j] = convert[i];
}
}
testValue = new HjorthClass(finalSeizureData);
textResult.setText("Value"+ testValue.returnVal());
if(testValue.returnSum()== true)
{
textResult.setText("Seizure has been detected in Text File");
}

}

}

霍斯级

public class HjorthClass extends Activity{
public double [][]Active;
public int height;
public int width;
public double [][] m0;
public double [][] threshold;
public double sum;
public double []temp;

//check length of height
public HjorthClass (double [][]Active)
{
height = Active[0].length;
width = Active[1].length;
m0 = new double[height][width];
threshold= new double[height][width];
sum = 0;


for(int i = 0; i<height; i++)// Original moving average - is used for Activity
{
if(i == 0)
{
m0[0][0] = Active[i][i];
}
else
{
for(int j =0; j < width; j++)
{
m0[i][j] = Active[i][j];
}
}
}



for(int i = 0; i<height; i++)
{
for(int j =0; j < width; j++)
{
if(m0[i][j] >= 1 )
{
threshold[i][j] = 1;
}
else
{
threshold[i][j]=0;
}
}
}

for(int i = 0; i<height; i++)// Sum of all the values
{
for(int j =0; j < width; j++)
{
sum = sum + threshold[i][j];
}
}
}
public boolean returnSum()
{
if(sum >= 300)
{
return true;
}
else
return false;
}

public double returnVal()
{
return sum;
}

}

最佳答案

回顾一下,您需要将 height = Active[0].length; 更改为 height = Active.length;

将二维数组视为数组的数组。所以Active是一个数组,Active[0]也是一个数组。 Active.length 是数组的数量,Active[0].length 是每个子数组的长度。希望有帮助!

关于java - 类不读取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22799802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com