/**
*
*/
package iSword;
import java.util.Date;
import java.util.Scanner;
/**
* @author iSword
*
*/
public class day_of_year {
/**题目:输入某年某月某日,判断这一天是这一年的第几天?
* @param args
*/
public static int[]i_31days=new int[]{1,3,5,7,8,10,12};
public static int[]i_30days=new int[]{4,6,9,11};
public int is_leap_year(int year){
if (((year%4==0)&(year%100!=0)) || (year%400==0)) return 1;
else return 0;
}
public int is_31days(int month){
int b=0;
for (int i=0;i<i_31days.length;i++){
if (month==i_31days[i]) b=1;
break;
}
return b;
}
public int is_30days(int month){
int b=0;
for (int i=0;i<i_30days.length;i++){
if (month==i_30days[i]) b=1;
break;
}
return b;
}
public int is_29days(int year){
day_of_year dy=new day_of_year();
int b=0;
if (dy.is_leap_year(year)==1) b=1;
return b;
}
public int is_28days(int year){
day_of_year dy=new day_of_year();
int b=0;
if (dy.is_leap_year(year)==0) b=1;
return b;
}
public int calculat_day(int year,int month, int day){
int count = 0;
day_of_year dy=new day_of_year();
//计算30天,31天的月份天数
for(int m=1;m<month;m++){
count=count+dy.is_31days(m)*31
+dy.is_30days(m)*30;
}
//计算2月份的天数:分leap year and !leap year
count=count+day+dy.is_29days(year)*29+dy.is_28days(year)*28;
return count;
//System.out.println(year+"-"+month+"-"+day+" is the "+count+"th days of year "+year);
}
/**
* 界面输入日期,计算天数
* @return
*/
public void interface_input(){
int year,month,day;
day_of_year dy=new day_of_year();
System.out.print("Please input the (year month day): ");
Scanner s = new Scanner(System.in);
year = s.nextInt();
month = s.nextInt();
day = s.nextInt();
int count=dy.calculat_day(year, month, day);
System.out.println(year+"-"+month+"-"+day+" is the "+count+"th days of year "+year);
}
/**
* 计算今天是今年的第多少天
* author 东海 陈光剑 chenguangjian
* Email: universsky@126.com
* Blog: http://blog.sina.com.cn/universsky11
* http://blog.csdn.net/universsky
*
*/
@SuppressWarnings("deprecation")
public void count_today(){
day_of_year dy=new day_of_year();
int t_year,t_month,t_day;
Date dt=new Date();
t_year=dt.getDate();
t_month=dt.getMonth();
t_day=dt.getDay();
int count=dy.calculat_day(t_year, t_month, t_day);
System.out.println("Today is the "+count+"th days of year "+ (1900+dt.getYear())+" ["+dt+"]");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//day_of_year dy=new day_of_year();
day_of_year dy=new day_of_year();
dy.interface_input();
dy.count_today();
}
}
/**
*
*/
package iSword;
import java.util.Date;
import java.util.Scanner;
/**
* 计算今天是今年的第多少天
* author 东海 陈光剑 chenguangjian
* Email: universsky@126.com
* Blog: http://blog.sina.com.cn/universsky11
* http://blog.csdn.net/universsky
*
*/
public class day_of_year {
public static int[]i_31days=new int[]{1,3,5,7,8,10,12};
public static int[]i_30days=new int[]{4,6,9,11};
public static void main(String[] args) {
day_of_year dy=new day_of_year();
int iput=dy.cal_days(2012, 6, 31);
System.out.println(iput);//151
Date date=new Date();
int cal_today=dy.cal_days(date.getYear(), date.getMonth(),date.getDay());
System.out.println("Today is the "+cal_today+"th days of year "+ (1900+date.getYear())+" ["+date+"]");
}
public int is_leap_year(int year){
if (((year%4==0)&(year%100!=0)) || (year%400==0)) return 1;
else return 0;
}
public int cal_days(int year,int month,int day){
int days = 0,d=0;
day_of_year dy=new day_of_year();
for (int i=1; i <month; i++) {
////////////////////////////////
if (i==2){
days=28+dy.is_leap_year(year);
}
else{
for (int j=0;j<i_31days.length;j++){
if (i==i_31days[j]) days = 31;
}
for (int k=0;k<i_30days.length;k++){
if (k==i_30days[k]) days = 30;
}
}
d += days;
}
//////////////////////////////////////
return d;
}
}
Q: 该程序有Bug, 如何白盒测试出来?
分享到:
相关推荐
PDF版本 陈光剑 共16章PDF版本 陈光剑 共16章PDF版本 陈光剑 共16章PDF版本 陈光剑 共16章PDF版本 陈光剑 共16章
本书带你快速进入Kotlin世界。本书基于Kotlin 1.1版本,从Kotlin基础知识到动手实战,包含了大量精选示例代码和应用案例。
《Kotlin从入门到进阶实战》_陈光剑
ClickHouse 设计哲学 具体问题具体分析 use good algorithms in a good context; 深入细节 dig into details; 度量指标 measure everything; 贴近生产环境 be close to production; 基准测试 do benchmarks, more of...
本书为《SpringBoot实战》中文版本,附带详细的目录标签。
在1964年的纽约世界博览会上,沃特·迪士尼向世界介绍了三件有开创意义的东西:“小小 世界”(it’s a small world)、“与林肯先生共度的伟大时刻”(Great Moments with Mr. Lincoln)以 及“文明演进之旋转木马...