判断某天为当年第几天的demo
2017-05-10 20:17
239 查看
package com.zhp.java; //用OOP 求出 某年某月某日是当年中的第几天 public class Day { private int y; private int m; private int d; int[] arr = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public Day(int y, int m, int d) { super(); this.y = y; this.m = m; this.d = d; } public Day() { super(); } public int getY() { return y; } public void setY(int y) { this.y = y; } public int getM() { return m; } public void setM(int m) { this.m = m; } public int getD() { return d; } public void setD(int d) { this.d = d; } // 判断是否为闰年 public boolean runNian() { if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) { return true; } else { return false; } } // 改变闰年二月的天数 public void two() { if (runNian()) { arr[2] = 29; } } @Override public String toString() { two(); int sum = 0; for (int i = 1; i < m; i++) { sum = sum + arr[i]; } return y + "年" + m + "月" + d + "日是" + y + "年的" + (sum + d) + "天"; } }
package com.zhp.java; import java.util.Scanner; public class DayDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入年份"); int y = sc.nextInt(); System.out.println("请输入月份"); int m = sc.nextInt(); System.out.println("请输入日期"); int d = sc.nextInt(); Day day = new Day(y, m, d); System.out.println(day.toString()); } }
相关文章推荐
- 输入一个日期,判断是当年的第几天
- C/C++学习:判断某日是当年第几天
- 计算某天在当年是第几天
- 第十二周项目五 判断当年第几天(数组法)
- 判断某天是某年的第几天
- switch case应用-输入年月日判断当年第几天
- 输入一个年月日,判断是当年的第几天
- 九宫格、函数入门、判断某天为某年的第几天
- 【学习笔记】判断某年某月某天是当年的第几天?
- [C#]数字颠倒输出;判断某天是一年中的第几天
- [C#]数字颠倒输出;判断某天是一年中的第几天
- 输入一个日期判断是当年的第几天
- 第十二周 用另一种方法判断某天是该年的第几天
- 编程基本功——判断某天是一年中的第几天
- 判断某年月日是当年的第几天
- 函数入门实例、九宫格实例、判断某日是当年的第几天实例
- 练习用数组判断某天是该年的第几天
- C#习题之输入年月日判断是当年第几天
- c语言输入年月日,判断是这一年的第几天
- 输入某年某月某日,判断这一天是这一年的第几天?