我有一个增量变量,我想将它存储到堆栈或数组中进行打印。
我的代码就像:
private Calendar schedule;
public void addScheduleNotificationFireEvent(List<Integer> scheduleList, long timeFromMeetingInSeconds){
schedule = Calendar.getInstance();
Log.d(DEBUG_TAG,"After Instance: " + schedule.getTimeInMillis());
long currentMillis = System.currentTimeMillis();
schedule.setTimeInMillis(currentMillis);
Log.d(DEBUG_TAG,"After setMillis: " + schedule.getTimeInMillis());
schedule.set(scheduleList.get(0),scheduleList.get(1),scheduleList.get(2),scheduleList.get(3),scheduleList.get(4),0);
Date scheduleTime = schedule.getTime();
long testCase = (((scheduleTime.getTime() - NOTIFICATION_FIRE_OFFEST_TIME - timeFromMeetingInSeconds*1000)-currentMillis)/1000);
Log.d(DEBUG_TAG,"TestCase Value: " + Long.toString(testCase));
Log.d(DEBUG_TAG,"schedtime: " + scheduleTime.getTime());
Log.d(DEBUG_TAG,"NOTIF_OFF: " + NOTIFICATION_FIRE_OFFEST_TIME);
Log.d(DEBUG_TAG, "TIME_MEETING: " + timeFromMeetingInSeconds*1000);
Log.d(DEBUG_TAG,"Current millis: " + currentMillis);
if(testCase > 0) {
Intent scheduleStepOutIntent = new Intent(mContext, MeetAppNotifierService.class)
.setAction("com.cyberfox.meetapp.SHOW_SCHEDULED_STEP_OUT_NOTIFICATION");
PendingIntent pi = PendingIntent.getService(mContext,0,scheduleStepOutIntent,PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
alarmManager.setExact(AlarmManager.RTC_WAKEUP,(scheduleTime.getTime()-NOTIFICATION_FIRE_OFFEST_TIME-timeFromMeetingInSeconds*1000),pi);
Log.d(DEBUG_TAG,"triggering at: " + testCase);
}
else{
Intent scheduleNotPossible = new Intent("MY_INTENT_HERE");
mContext.sendBroadcast(scheduleNotPossible);
}
schedule.clear();
schedule = null;
scheduleTime = null;
}
在这种情况下,正在发生的是打印计数器,但它是单独打印的。我希望我的输出结合如下。因此,我希望所有计数器值都存储在数组或堆栈中。
{
int counter = 0;
for(int i = 0; i < p; i++){
for (int j = 0; j < n; j++){
if (stringVal[p].equals(stringVal2[j]))
counter++;
}
System.out.println(counter);
}
}
有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
不是将所有计数器值存储在堆栈或数组中,而是可以在if条件下编写打印代码,如:
{
int counter = 0;
for(int i = 0; i < p; i++){
for (int j = 0; j < n; j++){
if (stringVal[p].equals(stringVal2[j]))
System.out.println(counter++);
}
}
}
上述方法可以节省时间和内存。