我正在制作一个添加数组值的程序。我的输入是这样的......
例如我将输入:
10-20,20-30,30-40
它会循环并且计算是这样的......
(10+20)+(20+30)+( 30+40)
我很难思考我将如何做到这一点..请帮助我..谢谢。
这是我的代码:
final AutoCompleteTextView interval_Values = (AutoCompleteTextView) findViewById(R.id.interval_Values);
final TextView txtArithmetc = (TextView) findViewById(R.id.txtArithmetic);
Button btncalculate = (Button) findViewById(R.id.btncalculate);
btncalculate.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
String[]x_value = interval_Values.getText().toString().split("-");
double[]value = new double[x_value.length];
String[]weight_value =interval_Values.getText().toString().split(",");
double[]value1 = new double[weight_value.length];
double sum = 0;
double sum1=0;
double result=0;
for(int i = 0; i < x_value.length; i++) {
value[i] = Double.parseDouble(x_value[i]);
sum+=value[i];
for(int a = 0; a < weight_value.length; a++) {
value1[a] = Double.parseDouble(weight_value[i]);
sum1+=value1[a];
}
result+= sum+sum1;
}
txtArithmetic.setText(Double.toString(result));<br/>