2014-09-10 16 views
-4

日曆從星期一開始,並返回1到int星期幾,我的代碼應該這樣做。我想不通當你把一個分號你if語句的結束下一步該怎麼做下一個,因爲所有我試過了,我得到了錯誤日曆從星期一開始,並返回1到int星期幾,我的代碼應該這樣做

import java.applet.Applet; 
import java.util.*; 
import java.awt.*; 

public class Dates2Applet extends Applet 
{ 
    public static void main(String[] args) 
    { 
    Calendar c = Calendar.getInstance(); 
    int wDay = c.get (Calendar.DAY_OF_WEEK); 

    if(Calendar.MONDAY == c.getFirstDayOfWeek()); 
    { 
     System.out.println("Monday is the first day of the week"); 
    } 

    if(Calendar.MONDAY == c.get(Calendar.DAY_OF_WEEK)); 
    { 
     System.out.println("Monday close books"); 
    } 

    if(Calendar.DAY_OF_WEEK == c.get(Calendar.DAY_OF_WEEK)); 
    { 
     System.out.println("Normal week day"); 
    } 

    if(Calendar.SATURDAY ==0 || Calendar.SUNDAY ==0); 
    { 
     System.out.println("Match Day"); 
    } 
} 

回答

1

它創建一個行身上,然後你的括號不依賴於if(這也是爲什麼,大概是else沒有爲你工作。) - 我想你想要的東西一樣,

if(Calendar.MONDAY == c.getFirstDayOfWeek()) { 
    System.out.println("Monday is the first day of the week"); 
} 
if(Calendar.MONDAY == c.get(Calendar.DAY_OF_WEEK)) { 
    System.out.println("Monday close books"); 
} else if(Calendar.DAY_OF_WEEK == c.get(Calendar.DAY_OF_WEEK)) { 
    System.out.println("Normal week day"); 
} else if(Calendar.SATURDAY ==0 || Calendar.SUNDAY ==0) { 
    System.out.println("Match Day"); 
} 
+0

我只是珍玩知道是如何形成的,你得到什麼的OP的問題希望? op使用的英文不清楚。以及爲什麼在明確作業時給出代碼呢!!!!! – 2014-09-10 16:47:36

+0

@KickButtowski我讀了OP張貼的代碼。 OP包含了這個代碼,不同之處在於不使用'else'並且在'if'塊上有分號。通常,';'在語義上不重要(但顯然它可以創建一個空的塊)。 – 2014-09-10 16:51:01

+0

@ElliottFrisch我只是想讓星期一的星期一回到1,希望星期天成爲一個7 – Bhabs 2014-09-10 17:06:00

相關問題