close
問題描述:
試撰寫一個程式,可由鍵盤讀入一個 4 位數的整數,代表西洋的年份,然後判別這個年份是否為閏年(每四年一閏,每百年不閏,每四百年一閏,例如西元 1900 雖為 4 的倍數,但可被 100 整除,所以不是閏年,同理, 2000 年是閏年,因可被 400 整數,而 2004 當然也是閏年,因可以被 4 整除)。
輸入說明:
輸入西元年份。
輸出說明:
輸出閏年(Bissextile Year)或平年(Common YearCommon Year)。
範例:
題目來源:http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=6947
import java.util.Scanner; public class C_MM35 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int a=scanner.nextInt(); if(a%400==0){ System.out.println("Bissextile Year"); }else if(a%100==0){ System.out.println("Common Year"); }else if(a%4==0){ System.out.println("Bissextile Year"); }else{ System.out.println("Common Year"); } } scanner.close(); } }
文章標籤
全站熱搜