zoukankan      html  css  js  c++  java
  • 表驱动法——直接访问表示例1

    方法一、直接访问表

    import java.util.Scanner;
    import java.util.Calendar;
    
    class DaysPerMonth {
        public static void main(String[] args) {
            
            System.out.println("输入年份:");
            Scanner scan = new Scanner(System.in);
            String input_year = scan.nextLine();
            int year = Integer.parseInt(input_year);
    
            System.out.println("输入月份:");
            String input_month = scan.nextLine();
            int month = Integer.parseInt(input_month);
    
            int days = daysPerMonth(year, month);
            System.out.println( year + " 年 " + month + " 月有 " + days + "天");
        }
    
        public static int daysPerMonth(int year, int month) {
            
            boolean flag = LeapYearIndex(year);
            System.out.println("是否是闰年?" + flag);
    
            if(flag) {
                int[] days = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
                return days[month-1];
            } else {
                int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
                return days[month-1];
            }
    
        }
    
        public static boolean LeapYearIndex(int year) {
            if ( ( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 ) {
                return true;
            } else {
                return false;
            }
        }
    
    }
  • 相关阅读:
    hdu 1535 Invitation Cards(spfa)
    hdu 1317 XYZZY
    hdu 1245 Saving James Bond
    hdu 1546 Idiomatic Phrases Game
    hdu 1217 Arbitrage(佛洛依德)
    hdu 1599 find the mincost route(无向图的最小环)
    poj1579
    poj1905
    poj1384
    poj3624
  • 原文地址:https://www.cnblogs.com/tzzt01/p/7420854.html
Copyright © 2011-2022 走看看