Friday, 15 January 2010

java - Find the nearest element with given element in list without using array -



java - Find the nearest element with given element in list without using array -

i have programme lastly value before given value. write that:

while (rs.next()) { int temp = rs.getint("alarmtype"); double fuel = rs.getdouble("nhienlieu"); if(temp != 60 ){ alarmtype = temp; double currentvalue = rs.getdouble("fuellevel"); double changevalue = lastvalue == 0 ? 0 : currentvalue + fuel - lastvalue; lastvalue = currentvalue; reportfuel = new fueldata( rs.getstring("accountid"), rs.getstring("deviceid"), rs.getint("timestamp"), rs.getdouble("latitude"), rs.getdouble("longitude"), rs.getstring("address"), currentvalue, rs.getdouble("odometerkm"), rs.getint("status"), changevalue, alarmtype, rs.getdouble("nhienlieu")); list.add(reportfuel); if(fuel > 0){ changevalue = fuel; } } }

in code, utilize temporary variable temp assign value of alarmtype, , check if temp not equal 60 print value before it(temp = 60)(only 1 value nearest). however, code seem print value satisfy condition. how can 1 value nearest temp = 60 without using array?

if understand correctly, help you:

fueldata tempfd = null; while(rs.next()){ int temp = rs.getint("alarmtype"); if(temp == 60 ){ //print or add together list tempfd tempfd = null; } else { tempfd = new fueldata(); } }

java

No comments:

Post a Comment