家庭作业帮助 [英] Homework help

查看:62
本文介绍了家庭作业帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面构造函数调用中需要什么参数来创建一个Date变量,其初始值是2004年3月15日????

解决方案

3 JAVA我需要回答的问题??!?


输入下面构造函数调用中所需的参数,以创建一个Date变量,其初始值为2004年3月15日。


日期d =新日期(____________);

------------------------- -------------------------------------------------- -----


[2]有一个名为DateFormat的标准类,除了其他功能之外,它还允许您将日期转换为各种不同的输出格式。


用它来编写一个名为convert的方法,它将日期转换为字符串形式为dd-mmm-yyyy:

public String convert(Date d ){

...

}


例如,当d是表示2006年12月25日的Date变量时,

String s = convert(d);


应将s设置为字符串25-Dec-2006。


在下面输入你的答案(只是你的转换方法):





--------------------------------------------- -----------------------------------


[3]写下if语句的条件,当日期d1不晚于日期d2时,该条件将为真:

if(____________________){

...

}


我没有安装Java了,但是看一下 DateFormat的Java API 。我注意到一个名为 parse(string s)的方法可以帮助你解决第一个问题。对于数字2,请查看格式(Date d,StringBuffer sb,FieldPosition fp)方法,以及getNumberFormat()。


我假设Date(0)相当于1月1日午夜,1979年,正如新的一年开始。时间以毫秒为单位,因此每个(1000 * 60 * 60 * 24 * 365.25 ... = 31557600000)大约相当于一年。有算法可以计算两个日期之间的天数。最后,如果每个日期都表示为毫秒数,那么您可以简单地比较代表日期的这两个数字。我假设已经为Date实现了小于运算符。


最简单的方法是使用DateFormat.parse(字符串源)解析日期,让Java完成所有这些计算所以Java为你计算了一个ms的时间。但是,以下是幕后进行的计算,以防您想了解。

闰年

展开 | 选择 | Wrap | 行号

what are the parameters needed in the constructor call below to create a Date variable whose intitial value is the 15th of March 2004????

解决方案

3 JAVA QUESTIONS THAT I NEED ANSWERING??!?!

Enter the parameters needed in the constructor call below to create a Date variable whose intitial value is the 15th of March 2004.

Date d = new Date( ____________ );
--------------------------------------------------------------------------------

[2] There is a standard class called DateFormat which (among other things) lets you convert dates to various different output formats.

Use it to write a method called convert which converts a Date to a String in the form dd-mmm-yyyy:
public String convert (Date d) {
...
}

For example, when d is a Date variable representing the 25th of December 2006,
String s = convert(d);

should set s to the string "25-Dec-2006".

Enter your answer (just your convert method) below:






--------------------------------------------------------------------------------

[3] Write a condition for the if statement below which will be true when the Date d1 is not later than the Date d2:
if ( ____________________ ) {
...
}


I don''t have Java installed anymore, but it may be helpful to look at the Java API for DateFormat. I noticed a method called parse(string s) that may help you with the first question. For number 2, look at the format(Date d, StringBuffer sb, FieldPosition fp) method, and maybe getNumberFormat().

I assume Date(0) is equivalent to midnight Jan 1, 1979, just as the new year began. The time is given in milliseconds, so then every (1000*60*60*24*365.25...=31557600000) is approximately equivalent to a year. There are algorithms to calculate how many days are in between two dates. Finally, if each date is represented as the number of milliseconds then you could simply compare these two numbers that represent the date. I am assuming the less than operator is already implemented for Date.


The easiest thing would be to parse the date, using DateFormat.parse(string source), and let Java do all those calculations so Java figures out a time in ms for you. However, here are the calculations that go on behind the scenes, in case you want to understand.

Leap years

Expand|Select|Wrap|Line Numbers


这篇关于家庭作业帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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