java中遍历数组时求和_java 数组元素如何循环求和

floatd[]=null;//定义一个空数组floatfmax=0;//定义一个消费最大值intlen=0;//为消费数据的个数try{rs=RecordStore.openRecordStore("record",true);len=rs.getNumRecords();d=newflo...

float d[] = null;//定义一个空数组

float fmax =0;//定义一个消费最大值

int len = 0;//为消费数据的个数

try {

rs=RecordStore.openRecordStore("record", true);

len=rs.getNumRecords();

d=new float[len];

RecordEnumeration re=rs.enumerateRecords(null, null, false);

int Index=len-1;

byte[] date;

while(re.hasNextElement()){

try{

date=re.nextRecord();

ByteArrayInputStream bais = new ByteArrayInputStream(date);

DataInputStream is = new DataInputStream(bais);

taste16 cd=new taste16();

cd.date=new Date();

cd.date.setTime(is.readLong());

cd.mu=is.readFloat();

d[Index]=cd.mu;

Index -=1;

if(cd.mu>fmax){

fmax=cd.mu;

}

is.close();

bais.close();

}catch(IOException e){

e.printStackTrace();

}

}

rs.closeRecordStore();

re.destroy();

} catch (RecordStoreFullException e) {

e.printStackTrace();

} catch (RecordStoreNotFoundException e) {

e.printStackTrace();

} catch (RecordStoreException e) {

e.printStackTrace();

}

上面为读取的数组,该使用什么方法求读取数组中元素的和

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值