Java練習


?編寫一個計算某個月份天數的程序,根據用戶輸入的月份,判斷并輸出該月份包含的天數。
package yue;
import java.util.Scanner;
public class yue {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請輸入一個月份:");? //輸入月份
?int month = input.nextInt();
?if(month==2)
?{
?System.out.println(month+"月閏年是29天,不是閏年則是28天");
?}
?else if(month==4||month==6||month==9||month==11)
?{
?System.out.println(month+"月是30天");
?}
? ? ?else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
? ? ?{
? ?? ?System.out.println(month+"月是31天");
? ? ?}?
}
}



標簽: