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 (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 with a certain status that have a time difference of over 24 hours):

 032394115-01
 032398720-01
 032395941-01
 032398165-01
 032395262-01
 032395350-01
 032392831-01

Now, if there aren't any claim numbers with a certain status that have a time difference of over 24 hours, I want my output to look like this:

No claim numbers meet this criteria.

How would I add that in there?

I tried doing this:

if(difference>86400000){                 
    System.out.println(singleClaim.getString("claimNumber"));
        } 
else{
 System.out.println("No claim numbers meet this criteria.");
 }

and changed the data to make sure no claim numbers had a difference greater than 24 hours but this is what I got as my output (the message displayed over and over again instead of the claim numbers):

No claim numbers meet this criteria.
No claim numbers meet this criteria.
No claim numbers meet this criteria.
No claim numbers meet this criteria.
No claim numbers meet this criteria.
No claim numbers meet this criteria.
2

There are 2 best solutions below

0
On

You would have to create a flag to tell if a claim has met the conditions. So outside your loop do something like:

boolean claimMet = false;

and in the if-statement:

if(difference>86400000){                 
    System.out.println(singleClaim.getString("claimNumber"));
    claimMet = true;
}

then after the loop ends:

 if (!claimMet) {
     System.out.println("No claim numbers meet this criteria.");
 }
0
On

I'm not sure I understood what you said, but let's try to answer it if I get it right :

boolean meetCriteria = false;

for(int difference = 0; ; difference++) {
    if(difference>86400000){                 
        meetCriteria = true;
    } 
} 

if(meetCriteria) {
    System.out.println(singleClaim.getString("claimNumber"));
} else {
    System.out.println("No claim numbers meet this criteria.");
}