博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
表驱动法——直接访问表示例1
阅读量:4310 次
发布时间:2019-06-06

本文共 1303 字,大约阅读时间需要 4 分钟。

《代码大全》看到“表驱动法”一章,以下是表驱动法的第一个方法——直接访问表

 

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;        }    }}

 

posted on
2017-08-23 23:37  阅读(
...) 评论(
...) 收藏

转载于:https://www.cnblogs.com/tzzt01/p/7420854.html

你可能感兴趣的文章
jenkins-小知识点
查看>>
visio二次开发——图纸解析
查看>>
如何在Windows Mobile下使用.NET Compact Framework画透明图片
查看>>
App后台开发架构实践笔记
查看>>
Set集合中的treeSet问题:cannot be cast to java.lang.Comparable;
查看>>
LeetCode-Maximum Product Subarray-最大乘积子数组-情况判断
查看>>
支付渠道路由系统进化史
查看>>
计算机领域会议和期刊
查看>>
shell 获得后台进程返回值
查看>>
python 多线程_thread
查看>>
SpringBoot2.0 + SpringCloud Eureka搭建高可用注册中心(Eureka之三)
查看>>
vue.js 组件-全局组件和局部组件
查看>>
svn 分支与合并的使用
查看>>
intellj idea
查看>>
浮动(clear)
查看>>
HierarchicalDataTemplate
查看>>
关于 keybd_event (vb篇)
查看>>
记公司的原型设计软件培训课程
查看>>
C语言知识点
查看>>
猴子吃桃
查看>>