(JAVA)在if语句试图打印数量的项目 [英] (Java) Trying to number printed items in an if statement
问题描述
所以,我有一个if语句的内部循环。我们的想法是,如果当前时间和已更新的时间之间的时间差大于24小时(或86400000毫秒),则打印出的权利要求编号。
这就是我if语句如下:
如果(差值> 86400000){
的System.out.println(singleClaim.getString(claimNumber));
}
和这是我的输出看起来像(索赔号码列表):
032394115-01
032398720-01
032395941-01
032398165-01
032395262-01
032395350-01
032392831-01
因为我有很多正在打印出来索赔数字,我希望能数得过来,使列表中的位更容易阅读。
类是这样的:
1)032394115-01
2)032398720-01
3)032395941-01
4)032398165-01
5)032395262-01
6)032395350-01
7)032392831-01
希望更多有经验的程序员比我会觉得这很容易。
编辑:我已经被告知,这将是有帮助的展示整个for循环,所以这里是如下:
为(的parseObject singleClaim:resultsList){
//如果customerStatus是5,我们检查,看看是否updatedTime不到24小时。
如果(singleClaim.getInt(customerStatus)== 5){
//创建一个日期格式。
SimpleDateFormat的格式化=新的SimpleDateFormat(YYYY-MM-dd'T'HH':'毫米':'SS SSS'Z'。');
//创建为今天的日期的日期对象。
日期的currentdate =新的日期();
//创建从解析日期字符串。
串parseTime = singleClaim.getString(updatedAt);
//初始化日期对象的updatedAt时间解析。
日期parseDate = NULL;
尝试{
//这里,我们转换parseTime字符串转换成Date对象,并对其进行格式化。
parseDate = formatter.parse(parseTime);
}
赶上(例外五){
e.printStackTrace();
}
//获得从当前日期与以毫秒为单位的解析的时间的时间差。
长差= currentDate.getTime() - parseDate.getTime();
的for(int i = 1 ;;我++){
//如果时间差是在毫秒时间超过24小时,我们打印出要求数量。
如果(差值> 86400000){
的System.out.println第(i +。)+ singleClaim.getString(claimNumber));
}
其他{
打破;};
}
}}
的System.out.println(\\ n ///////////////////////////////////////// ///////////////);
的System.out.println(完成获得索赔与5更新超过24小时前customerStatus。);
的System.out.println(/////////////////////////////////////////// //////////// \\ n);
}
赶上(例外五){
e.printStackTrace();
}}}
使用计数器:
如果(差值> 86400000){
的System.out.println(计数器++ +。)+ singleClaim.getString(claimNumber));
}
先初始化柜台您的循环:
INT计数器= 1;
So, I have an if statement inside of a for loop. The idea is, if the time difference between the current time and an updated time is greater than 24 hours (or 86400000 milliseconds), then I print out the claim number.
This what my if statement looks like:
if(difference>86400000){
System.out.println(singleClaim.getString("claimNumber"));
}
and this is what my output looks like (a list of claim numbers):
032394115-01
032398720-01
032395941-01
032398165-01
032395262-01
032395350-01
032392831-01
Since I have a lot of claim numbers that are being printed out, I was hoping to number them to make the list a bit easier to read.
Kind of like this:
1.) 032394115-01
2.) 032398720-01
3.) 032395941-01
4.) 032398165-01
5.) 032395262-01
6.) 032395350-01
7.) 032392831-01
Hopefully more experienced programmers than myself will find this fairly easy.
EDIT: I've been told that it would be helpful to show the entire for loop, so here it is below:
for(ParseObject singleClaim : resultsList){
//If the customerStatus is 5, we check to see if the updatedTime is within 24 Hours.
if(singleClaim.getInt("customerStatus") == 5) {
//Create a date formatter.
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd'T'HH':'mm':'ss'.'SSS'Z'");
//Create a date object for today's date.
Date currentDate=new Date();
//Create a string for the date from parse.
String parseTime = singleClaim.getString("updatedAt");
//Initialize the date object for the updatedAt time on Parse.
Date parseDate = null;
try {
//Here, we convert the parseTime string into a date object and format it.
parseDate = formatter.parse(parseTime);
}
catch (Exception e) {
e.printStackTrace();
}
//Get the time difference from the current date versus the date on Parse in milliseconds.
long difference = currentDate.getTime() - parseDate.getTime();
for(int i=1;;i++ ){
//If the time difference is more than 24 hours in milliseconds, we print out the claim number.
if(difference>86400000){
System.out.println(i + ".)" + singleClaim.getString("claimNumber"));
}
else {
break;};
}
}}
System.out.println("\n////////////////////////////////////////////////////////");
System.out.println("Done getting claims with customerStatus of 5 updated over 24 hours ago.");
System.out.println("///////////////////////////////////////////////////////\n");
}
catch(Exception e){
e.printStackTrace();
}}}
Use a counter :
if(difference>86400000) {
System.out.println(counter++ + ".)" + singleClaim.getString("claimNumber"));
}
Initialize the counter prior to your loop :
int counter = 1;
这篇关于(JAVA)在if语句试图打印数量的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!