Calendar问题(新手)

KG071 2010-06-23 12:30:15
代码如下:

import java.util.*;

public class Test6_1 {
public static void main(String[] args) {
int i=0,n;
System.out.println(" 日 一 二 三 四 五 六 ");
Calendar cal = Calendar.getInstance();
int y = Integer.parseInt(args[0]);
int m = Integer.parseInt(args[1]);
int d = Integer.parseInt(args[2]);
cal.set(y,m,d);
int weekday = cal.get(Calendar.DAY_OF_WEEK)-1; // 1 应该是这里出现问题
//格式化输出
for(i=0; i<weekday; i++) {
if(i==0) System.out.print(" ");
System.out.print(" ");
}
for(n=1; i<weekday + 31 ; i++) {
if(i%7 == 0) System.out.print("\n ");
if(n < 10) System.out.print(" ");
System.out.print(n + " ");
n++;
}
}
}

我想输出1989年12月的日历,但是结果不对。

运行结果:
d:\我的文档\桌面\ceshi>javac Test6_1.java

d:\我的文档\桌面\ceshi>java Test6_1 1989 12 1
日 一 二 三 四 五 六
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

1989年12月1日应该是周五啊,应该是注释1处有问题,但不知出现了什么问题!!希望各位帮忙看看!
...全文
89 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gaoxiang519 2010-06-23
  • 打赏
  • 举报
回复
楼上正解
qianzhimeiying 2010-06-23
  • 打赏
  • 举报
回复
另:楼主出生于1989年12月,鉴定完毕
qianzhimeiying 2010-06-23
  • 打赏
  • 举报
回复
月的取值范围是0-11
int m = Integer.parseInt(args[1])-1;
KG071 2010-06-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 qianzhimeiying 的回复:]
月的取值范围是0-11
int m = Integer.parseInt(args[1])-1;
[/Quote]

对了 找到问题了 谢谢大家
ronniegxq 2010-06-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 qianzhimeiying 的回复:]

另:楼主出生于1989年12月,鉴定完毕
[/Quote]
qq736204439 2010-06-23
  • 打赏
  • 举报
回复
int weekday = cal.get(Calendar.DAY_OF_WEEK)-1;

改为 int j = 0;
while(weekday != Calendar.fristDayOfWeek){

j ++;
cal.add(Calendar.DAY_OF_MONTH,-1);
weekday = cal.get(Calendar.DAY_OF_WEEK);

}
for(int i = 0;i < j ;i ++){
System.out.print(" ");
}
hoojo 2010-06-23
  • 打赏
  • 举报
回复
老外什么东西都是从0开始的,传说是老外的楼房有地下室,地下室是0。所以array的索引从0开始……
此程序我运用的都是C++基础知识,方便新手学习理解,在VC6.0上测试0错误0警告,可放心使用,在此衷心希望大家学习进步 以下是题目 Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day long year, called Haab, which had 19 months. Each of the first 18 months was 20 days long, and the names of the months were pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu. Instead of having names, the days of the months were denoted by numbers starting from 0 to 19. The last month of Haab was called uayet and had 5 days denoted by numbers 0, 1, 2, 3, 4. The Maya believed that this month was unlucky, the court of justice was not in session, the trade stopped, people did not even sweep the floor. For religious purposes, the Maya used another calendar in which the year was called Tzolkin (holly year). The year was divided into thirteen periods, each 20 days long. Each day was denoted by a pair consisting of a number and the name of the day. They used 20 names: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers; both in cycles. Notice that each day has an unambiguous description. For example, at the beginning of the year the days were described as follows: 1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, and again in the next period 8 imix, 9 ik, 10 akbal . . . Years (both Haab and Tzolkin) were denoted by numbers 0, 1, : : : , where the number 0 was the beginning of the world. Thus, the first day was: Haab: 0. pop 0 Tzolkin: 1 imix 0 Help professor M. A. Ya and write a program for him to convert the dates from the Haab calendar to the Tzolkin calendar. Input The date in Haab is given in the following format: NumberOfTheDay. Month Year The first line of the input file contains the number of the input dates in the file. The next n lines contain n dates in the Haab calendar format, each in separate line. The year is smaller then 5000. Output The date in Tzolkin should be in the following format: Number NameOfTheDay Year The first line of the output file contains the number of the output dates. In the next n lines, there are dates in the Tzolkin calendar format, in the order corresponding to the input dates. Sample Input 3 10. zac 0 0. pop 0 10. zac 1995 Sample Output 3 3 chuen 0 1 imix 0 9 cimi 2801

62,630

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧