JAVA編程------------輸入某年某月某日,判斷這一天是這一年的第幾天


 1 package FushiExam;
 2 import java.util.*;
 3 public class Text_14 {
 4 
 5     public static void main(String[] args) {
 6         // 輸入某年某月某日,判斷這一天是這一年的第幾天
 7         Scanner scan=new Scanner(System.in);
 8         int year=scan.nextInt();
 9         int month=scan.nextInt();
10         int day=scan.nextInt();
11         int total=0;
12         if(year%400==0||(year%100!=0&&year%4==0)) {//閏年
13             int[] months= {31,29,31,30,31,30,31,31,30,31,30,31};
14         for(int i=0;i<month-1;i++) {
15             total=total+months[i];
16         }
17         total=total+day;
18             System.out.println("這是這一年的第"+total+"天");
19         }
20         else {//非閏年
21             int[] months= {31,28,31,30,31,30,31,31,30,31,30,31};
22             for(int i=0;i<month-1;i++) {
23                 total=total+months[i];
24             }
25             total=total+day;
26                 System.out.println("這是這一年的第"+total+"天");
27         }
28             
29         
30 
31     }
32 
33 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM