猿问

java在for循环中怎样修改参数值?

//待认证
QueryFilterqueryFilter0=newQueryFilter();
queryFilter0.addCommand(newCommand("busStatus",Op.EQ,"0"));
inttaxStatus0=taxInfoDao.getCount(queryFilter0);
intbusinessStatus0=businessInfoDao.getCount(queryFilter0);
intsocialSecurityStatus0=socialSecurityDao.getCount(queryFilter0);
intstatus0=taxStatus0+businessStatus0+socialSecurityStatus0;
//待审核
QueryFilterqueryFilter1=newQueryFilter();
queryFilter1.addCommand(newCommand("busStatus",Op.EQ,"1"));
inttaxStatus1=taxInfoDao.getCount(queryFilter1);
intbusinessStatus1=businessInfoDao.getCount(queryFilter1);
intsocialSecurityStatus1=socialSecurityDao.getCount(queryFilter1);
intstatus1=taxStatus1+businessStatus1+socialSecurityStatus1;
//已通过
QueryFilterqueryFilter2=newQueryFilter();
queryFilter2.addCommand(newCommand("busStatus",Op.EQ,"2"));
inttaxStatus2=taxInfoDao.getCount(queryFilter2);
intbusinessStatus2=businessInfoDao.getCount(queryFilter2);
intsocialSecurityStatus2=socialSecurityDao.getCount(queryFilter2);
intstatus2=taxStatus2+businessStatus2+socialSecurityStatus2;
//未通过
QueryFilterqueryFilter3=newQueryFilter();
queryFilter3.addCommand(newCommand("busStatus",Op.EQ,"3"));
inttaxStatus3=taxInfoDao.getCount(queryFilter3);
intbusinessStatus3=businessInfoDao.getCount(queryFilter3);
intsocialSecurityStatus3=socialSecurityDao.getCount(queryFilter3);
intstatus3=taxStatus3+businessStatus3+socialSecurityStatus3;
这样的代码从status0到status3有4组java有没有这种功能,写一个函数,里面用for循环
JSONObjectresult=newJSONObject();
for(inti=0;i<4;i++){
QueryFilterqueryFilteri=newQueryFilter();
queryFilteri.addCommand(newCommand("busStatus",Op.EQ,"i"));
inttaxStatusi=taxInfoDao.getCount(queryFilteri);
intbusinessStatusi=businessInfoDao.getCount(queryFilteri);
intsocialSecurityStatusi=socialSecurityDao.getCount(queryFilteri);
intresult=taxStatusi+businessStatusi+socialSecurityStatusi;
result.put("statusi",statusi);
}
当然我这样写是错的,但是有没有什么功能能实现这个函数?
慕桂英4014372
浏览 883回答 2
2回答

精慕HU

这难道不应该用数组去实现吗?恭喜你,看到一坨屎一样的代码想要把它优化是成长为一名高级工程师的必经之路,你看那些大师们身上都是屎迹斑斑。QueryFilter[]queryFilter=newQueryFilter[4];int[]taxStatus=newint[4];int[]businessStatus=newint[4];int[]socialSecurityStatus=newint[4];int[]status=newint[4];for(inti=0;i

幕布斯7119047

只需稍加改动:JSONObjectresult=newJSONObject();for(inti=0;i
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答