你能帮忙解释一下这个鳕鱼的意义和意义吗? [英] Can You Help To Explain This Cod What Dose It Mean And What It Do ?

查看:72
本文介绍了你能帮忙解释一下这个鳕鱼的意义和意义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private int checkDay( int testDay )
{
      int daysperMonth [] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
       // check if day in rang for month
      if (testDay >0 && testDay <= daysperMonth[month])
         return testDay ;
         // check for leap year

      if (month ==2 && testDay ==24 &&(year %400 ==0 || (year %4 ==0 && year %100!=0) ) )
         return testDay ;
         System.out.printf ("Invalid day (%d) set to 1 ", testDay);
         return 1 ; // maintain object n consistent state
     } // end method checkDay 

推荐答案

它看着提供的日期信息,并决定日期是否有效。



但是,它不起作用。没有一个月只有24天,即使在闰年......

并且它返回的信息很差:bool有效/无效检查会更加明智。
It looks at the date information provided and decides if the date is valid.

However, it doesn't work. No month has only 24 days, even in a leap year...
And it returns poor information: a bool valid/invalid check would be a lot more sensible.


此代码检查给定日期是否在日历中(即它的数字是在当前月份的最小和最大数字之间)。



以下行

This code is checking if the given day is in the calendar (that is its number is between current month's minimum and maximum number).

The following line
Quote:

if (月== 2&& testDay == 24&&(年%400 == 0 ||(年%4 == 0&&年%100!= 0)))

if (month ==2 && testDay ==24 &&(year %400 ==0 || (year %4 ==0 && year %100!=0) ) )





错误:它应该是



Is wrong: it should be

if (month ==2 && testDay ==29 && (year %400 ==0 || (year %4 ==0 && year %100!=0) ) )



检查 29 2月份是有效的一天,也就是当前年份是闰年

你知道,如果它可以被<$ c整除,那么它就是一年的飞跃$ c> 4 但它不是一个世纪的年份(例如 1900 ),除非它也可以被 400整除(例如 2000 )。



顺便说一句,缩进是错误的ng。



[更新]

OriginalGriff 所述(我忽略了它)


It checks if 29th of february is a valid day, that is if current year is a leap year.
You know, a year is leap if it is exactly divisible by 4 but it isn't a century year (e.g. 1900), unless it is also divisible by 400 (e.g. 2000).

By the way, the indentation is misleading.

[update]
As noted by OriginalGriff (I have overlooked it)

Quote:

返回1; //保持对象n一致状态

return 1 ; // maintain object n consistent state



简直就是疯狂:如果你检测到无效输入,你必须发出信号。

[/ update]


is plain madness: if you detect an invalid input, you have to signal it.
[/update]


这篇关于你能帮忙解释一下这个鳕鱼的意义和意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆