用Java语言编写个日历程序
2个回答
展开全部
class CalendarList{
int year,month;
int dayNum,i,num,count=0;
Calendar objCalendar;
int[] arrDayNum=;
CalendarList(){
objCalendar=Calendar.getInstance();
this.year=objCalendar.get(Calendar.YEAR);
this.month=objCalendar.get(Calendar.MONTH)+1; //要+1
}
CalendarList(String args0,String args1){
this.year=Integer.parseInt(args1);
this.month=Integer.parseInt(args0);
objCalendar=Calendar.getInstance();//这里没有get
objCalendar.set(Calendar.YEAR,year);//set是这样用的
objCalendar.set(Calendar.MONTH,month-1);
}
void display(){
System.out.println("\t\t\t"+year+"年"+month+"月");
System.out.println("日 一 二 三 四 五 六"); //每个空3个空格
num=objCalendar.get(Calendar.DAY_OF_WEEK);
if ((year/4==0&&year/100!=0)||(year/400==0)){
arrDayNum[1]+=1;
}
for (i=1;i<=12;i++){
if (i==month){
dayNum=arrDayNum[i-1];
break;
}
}
for(i=1;i<=num;i++){
System.out.print(" ");//5个空格
count++;
}
for (i=1;i<=dayNum;i++){
System.out.print(i<10?" "+i+" ":i+" "); //自己改了下 ,空格数:1,3,3
count++;
if(count==7){
System.out.println();
count=0;
}
}
System.out.println ();
}
}
public class MainClass {
public static void main(String[] args) {
CalendarList objCalendar=new CalendarList();
CalendarList objCalendar1=new CalendarList("11","2007");
objCalendar.display();
objCalendar1.display();
}
}
int year,month;
int dayNum,i,num,count=0;
Calendar objCalendar;
int[] arrDayNum=;
CalendarList(){
objCalendar=Calendar.getInstance();
this.year=objCalendar.get(Calendar.YEAR);
this.month=objCalendar.get(Calendar.MONTH)+1; //要+1
}
CalendarList(String args0,String args1){
this.year=Integer.parseInt(args1);
this.month=Integer.parseInt(args0);
objCalendar=Calendar.getInstance();//这里没有get
objCalendar.set(Calendar.YEAR,year);//set是这样用的
objCalendar.set(Calendar.MONTH,month-1);
}
void display(){
System.out.println("\t\t\t"+year+"年"+month+"月");
System.out.println("日 一 二 三 四 五 六"); //每个空3个空格
num=objCalendar.get(Calendar.DAY_OF_WEEK);
if ((year/4==0&&year/100!=0)||(year/400==0)){
arrDayNum[1]+=1;
}
for (i=1;i<=12;i++){
if (i==month){
dayNum=arrDayNum[i-1];
break;
}
}
for(i=1;i<=num;i++){
System.out.print(" ");//5个空格
count++;
}
for (i=1;i<=dayNum;i++){
System.out.print(i<10?" "+i+" ":i+" "); //自己改了下 ,空格数:1,3,3
count++;
if(count==7){
System.out.println();
count=0;
}
}
System.out.println ();
}
}
public class MainClass {
public static void main(String[] args) {
CalendarList objCalendar=new CalendarList();
CalendarList objCalendar1=new CalendarList("11","2007");
objCalendar.display();
objCalendar1.display();
}
}
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
展开全部
<html>
<head>
<title>Cool日历</title>
</head><BODY background="../images/bg.gif">
<!--将以下代码加入HTML的<Body></Body>之间-->
<script language="JavaScript">
<!-- Hide this script from old browsers --
function greeting()
{
var today = new Date();
var hrs = today.getHours();
document.writeln("<CENTER>");
document.write("Good ");
if (hrs < 6)
document.write("(Early) Morning");
else if (hrs < 12)
document.write("Morning");
else if (hrs <= 18)
document.write("Afternoon");
else
document.write("Evening");
document.write("!");
document.write("当前时间是:");
dayStr = today.toLocaleString();
document.write(dayStr);
document.writeln("</CENTER>");
}
function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
this[0] = m0;
this[1] = m1;
this[2] = m2;
this[3] = m3;
this[4] = m4;
this[5] = m5;
this[6] = m6;
this[7] = m7;
this[8] = m8;
this[9] = m9;
this[10] = m10;
this[11] = m11;
}
function calendar()
{
var today = new Date();
var thisDay;
var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30,
31, 30, 31);
year = today.getYear();
if (year<2000)
year=year+1900;
thisDay = today.getDate();
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
monthDays[1] = 29;
nDays = monthDays[today.getMonth()];
firstDay = today;
firstDay.setDate(1); // works fine for most systems
testMe = firstDay.getDate();
if (testMe == 2)
firstDay.setDate(0);
startDay = firstDay.getDay();
document.writeln("<CENTER>");
document.write("<TABLE BORDER bgcolor=moccasin>");
document.write("<TR><TH COLSPAN=7>");
document.write(year+'年');
document.write(today.getMonth()+1+'月');
document.write("<TR><TH>日<TH>一<TH>二<TH>三<TH>四<TH>五<TH>六");
document.write("<TR>");
column = 0;
for (i=0; i<startDay; i++)
{
document.write("<TD>");
column++;
}
for (i=1; i<=nDays; i++)
{
document.write("<TD>");
if (i == thisDay)
document.write("<FONT COLOR=\"red\">")
document.write(i);
if (i == thisDay)
document.write("</FONT>")
column++;
if (column == 7)
{
document.write("<TR>");
column = 0;
}
}
document.write("</TABLE>");
document.writeln("</CENTER>");
}
greeting();
document.write("<br>");
calendar();
document.write("");
// -- End Hiding Here -->
</script>
</body></html>
<head>
<title>Cool日历</title>
</head><BODY background="../images/bg.gif">
<!--将以下代码加入HTML的<Body></Body>之间-->
<script language="JavaScript">
<!-- Hide this script from old browsers --
function greeting()
{
var today = new Date();
var hrs = today.getHours();
document.writeln("<CENTER>");
document.write("Good ");
if (hrs < 6)
document.write("(Early) Morning");
else if (hrs < 12)
document.write("Morning");
else if (hrs <= 18)
document.write("Afternoon");
else
document.write("Evening");
document.write("!");
document.write("当前时间是:");
dayStr = today.toLocaleString();
document.write(dayStr);
document.writeln("</CENTER>");
}
function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
this[0] = m0;
this[1] = m1;
this[2] = m2;
this[3] = m3;
this[4] = m4;
this[5] = m5;
this[6] = m6;
this[7] = m7;
this[8] = m8;
this[9] = m9;
this[10] = m10;
this[11] = m11;
}
function calendar()
{
var today = new Date();
var thisDay;
var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30,
31, 30, 31);
year = today.getYear();
if (year<2000)
year=year+1900;
thisDay = today.getDate();
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
monthDays[1] = 29;
nDays = monthDays[today.getMonth()];
firstDay = today;
firstDay.setDate(1); // works fine for most systems
testMe = firstDay.getDate();
if (testMe == 2)
firstDay.setDate(0);
startDay = firstDay.getDay();
document.writeln("<CENTER>");
document.write("<TABLE BORDER bgcolor=moccasin>");
document.write("<TR><TH COLSPAN=7>");
document.write(year+'年');
document.write(today.getMonth()+1+'月');
document.write("<TR><TH>日<TH>一<TH>二<TH>三<TH>四<TH>五<TH>六");
document.write("<TR>");
column = 0;
for (i=0; i<startDay; i++)
{
document.write("<TD>");
column++;
}
for (i=1; i<=nDays; i++)
{
document.write("<TD>");
if (i == thisDay)
document.write("<FONT COLOR=\"red\">")
document.write(i);
if (i == thisDay)
document.write("</FONT>")
column++;
if (column == 7)
{
document.write("<TR>");
column = 0;
}
}
document.write("</TABLE>");
document.writeln("</CENTER>");
}
greeting();
document.write("<br>");
calendar();
document.write("");
// -- End Hiding Here -->
</script>
</body></html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |