这是我的代码,我有一个简单的问题
import java.util.*;
import java.io.*;
import type.lib.GlobalCredit;
import type.lib.CreditCard;
import java.text.SimpleDateFormat;
public class eCheck08A
{
public static void main(String[] args)
{
PrintStream out = System.out;
Scanner in = new Scanner(System.in);
GlobalCredit credit1 = new GlobalCredit().getRandom();
out.print("Enter report range in years ... ");
int range = in.nextInt();
out.println("Cards expiring before " + range + " year(s) from now: ");
SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
for (CreditCard cc : credit1)
{
Calendar c = Calendar.getInstance();
c.setTime(cc.getExpiryDate());
c.add(Calendar.YEAR, range);
Date newDate = c.getTime();
if (cc.getExpiryDate().compareTo(newDate) < range)
{
if(cc.getExpiryDate().compareTo(newDate) > range)
{
out.print("*");
}
out.print(cc.getNumber());
out.println("\t" + sf.format(cc.getExpiryDate()));
}
}
}
}
它应该是什么样子的输出:
Enter report range in years ... 3
Cards expiring before 3 years from now:
561561-8 20/11/2015
045645-7 22/02/2017
456462-3 16/04/2013 *
546548-5 19/08/2016
当前年份是 2012 该人输入“3”作为范围。所以从 2012 年到 2015 年的任何年份都应该有一个“*”。和上面的输出一样,2013 有一个“*”。你能告诉我在我的 IF 语句中做错了什么吗?