這是我的代碼,我有一個簡單的問題,它應該是什麼樣子IF語句條件
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聲明中做錯了嗎?
檢查['Date.compareTo']的javadocs(http://docs.oracle.com/javase/6/docs/api/java/util/Date.html#compareTo%28java.util.Date% 29),它不能保證是>或<範圍的值,只是>或<0 – 2012-07-25 06:04:07
我是* sooo *添加[tag:homework]標籤... – Bohemian 2012-07-25 06:13:12
我們是否有類似的問題幾天之前? – MadProgrammer 2012-07-25 06:32:47