zoukankan      html  css  js  c++  java
  • 例题

    输入某年某月某日,判断这一天是这一年的第几天?

    package a;
    import java.util.*;
    public class ScannerTest {
    public static void main(String[] args) {
    int year, month, day;
    int days = 0;
    int d = 0;
    int e;
    input fymd = new input();
    do {
    e = 0;
    System.out.print("输入年:");
    year = fymd.input();
    System.out.print("输入月:");
    month = fymd.input();
    System.out.print("输入天:");
    day = fymd.input();
    if (year < 0 || month < 0 || month > 12 || day < 0 || day > 31) {
    System.out.println("输入错误,请重新输入!");
    e = 1;
    }
    } while (e == 1);
    for (int i = 1; i < month; i++) {
    switch (i) {
    case 1:

    case 3:

    case 5:

    case 7:

    case 8:

    case 10:

    case 12:
    days = 31;
    break;
    case 4:

    case 6:

    case 9:

    case 11:
    days = 30;
    break;
    case 2:
    if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
    days = 29;
    } else {
    days = 28;
    }
    break;
    }
    d += days;
    }
    System.out.println(year + "-" + month + "-" + day + "是这年的第" + (d + day) + "天。");
    }
    }

    class input {
    public int input() {
    int value = 0;
    Scanner s = new Scanner(System.in);
    value = s.nextInt();
    return value;
    }
    }

    输出9*9口诀。

  • 相关阅读:
    PetaLinux 生成 Zynq 操作系统
    单片机、微控制器和微处理器有什么区别
    嵌入式基础概念系列(1) —— GPIO
    学中杂记
    Spring学习笔记
    jdbc一点小笔记
    JSP学习
    Servlet学习的一些笔记
    接触Struts2的ModelDriven<>接口
    android-dialog的位置
  • 原文地址:https://www.cnblogs.com/mjhjl/p/13584080.html
Copyright © 2011-2022 走看看