JAVA-GetDay

来源:互联网 发布:pdf格式软件下载 编辑:程序博客网 时间:2024/05/15 05:36

import java.util.*;

public class Ch0310 {

public static void main(String[] args) {    // TODO 自动生成的方法存根    Scanner in = new Scanner(System.in);    System.out.println("输入年份:");    int year = in.nextInt();    System.out.println("输入月份:");    int month = in.nextInt();    System.out.println("输入日期:");    int day = in.nextInt();    int a = day;    for (int i = 0; i < month; i++) {        switch (i) {        case 1:        case 3:        case 5:        case 7:        case 8:        case 10:        case 12:            a += 31;            break;        case 4:        case 6:        case 9:        case 11:            a += 30;            break;        case 2:            if (year % 100 != 0 && year % 4 == 0 || year % 400 == 0) {                a += 29;            } else {                a += 28;            }            break;        default:            break;        }    }    System.out.println(year + "年" + month + "月" + day + "日是这年的第" + a + "天");    in.close();}

}

0 0
原创粉丝点击