java 循环内产生不同的变量名_使用Java中的循环创建变量名称?

第一次海报,长时间读者所以对我温柔:)

请参阅以下代码,该代码用于生成财务年度中每月开始和结束的时间戳.

int year = 2010;

// Financial year runs from Sept-Aug so earlyMonths are those where year = FY-1 and lateMonths are those where year = FY

int[] earlyMonths = {8, 9, 10, 11}; // Sept to Dec

int earlyYear = year -1;

for (int i : earlyMonths) {

month = i;

Calendar cal = Calendar.getInstance();

cal.clear();

cal.set(earlyYear,month,1,0,0,0);

Long start = cal.getTimeInMillis();

cal.clear();

cal.set(earlyYear,month,1);

lastDayofMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);

cal.set(earlyYear,month,lastDayofMonth,23,59,59);

Long end = cal.getTimeInMillis();

}

int[] lateMonths = {0, 1, 2, 3, 4, 5, 6, 7}; // Jan to Aug

for (int i : lateMonths) {

month = i;

Calendar cal = Calendar.getInstance();

cal.clear();

cal.set(year,month,1,0,0,0);

Long start = cal.getTimeInMillis();

cal.clear();

cal.set(year,month,1);

lastDayofMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);

cal.set(year,month,lastDayofMonth,23,59,59);

Long end = cal.getTimeInMillis();

}

到目前为止这么好,但是为了使用这些结果,我需要将这些时间戳输出到以月命名的变量(稍后在代码中用于预备语句.例如SeptStart = sometimestamp,SeptEnd = some timestamp等等.

我不知道是否可以根据每个循环的结果声明新变量.有任何想法吗?

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值