菜鸟求大神赐教哇~~~

shitoucyz 2012-10-31 07:38:39
package com.mysoft.test;

import java.util.*;
public class Calendar{
private static Object DAY_OF_WEEK;




public void printCalcn(int year,int month)
{
Calendar myca=Calendar.getInstance();
myca.set(year,month-1,1);
int week=myca.get(Calendar.DAY_OF_WEEK);
int days=this.getDaysOfMonths(year,month);
int w=0;
System.out.println(" 日 一 二 三 四 五 六 ");
for(int j=1;j<=days;j++)
{
if(j==1)
for(int i=1;i<week;i++)
{
System.out.print(" ");
w++;
}
if(j<10){
System.out.print(" "+j);
}
else{
System.out.print(" "+j);
}
w++;
if(w%7==0)
System.out.println();
}
}




private int getDaysOfMonths(int year, int month) {
int days=0;
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:

days=31;
break;
case 4:
case 6:
case 9:
case 11:

days=30;
break;
case 2:
if((year%4==0)||(year%400==0))
days=29;
else
days=28;
}
return days;
}




public static void main(String[] args) {
Calendar Cal1=new Calendar();
Cal1.printCalcn(2012, 10);
}

}



这个程序怎么改??
...全文
138 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shitoucyz 2012-11-01
  • 打赏
  • 举报
回复
国际化怎么弄?[Quote=引用 5 楼 的回复:]

package com.fzw.test.graph;

import java.util.Calendar;

public class Year {
public void myCalendar()
{

int year = (int)(Math.random()* 1000)+2000;

……
[/Quote]
oLeopard123 2012-11-01
  • 打赏
  • 举报
回复
package com.fzw.test.graph;

import java.util.Calendar;

public class Year {
public void myCalendar()
{

int year = (int)(Math.random()* 1000)+2000;

Calendar calendar = Calendar.getInstance();
//calendar.set(year, 2, 1);
int day = 28;
boolean isLeap = judge(year);
int week = calendar.get(calendar.DAY_OF_WEEK) - 1;
System.out.println(year + "年2月的日历页:");
System.out.println("日 一 二 三 四 五 六");
if(isLeap)
day = 29;
String a[] = new String[week + day];

for(int x = 0; x < week; x++)
{
a[x] = " ";
}

for(int i = week, n = 1; i < a.length; i++)
{
if(n <= 9)
a[i] = String.valueOf(n) + " ";
else
a[i] = String.valueOf(n);
n++;
}

for(int j = 0; j < a.length; j++)
{
if(j % 7 == 0)
{
System.out.println();
}
System.out.print(" " + a[j]);
}

}

public static boolean judge(int year)
{
boolean yearleap = (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0);//采用布尔数据计算判断是否能整除
return yearleap;
}
}



package com.fzw.test.graph;

public class Test {
public static void main(String[] args) {
Year year = new Year();
year.myCalendar();
}
}
  • 打赏
  • 举报
回复
没细看,不过你的
case 2:
if((year%4==0)||(year%400==0))
days=29;
else
days=28;
}
这块代码的逻辑肯定是不对的,后面(year%400==0)是不可能执行的,最关键的是,你的闰年规则没弄清楚。
闰年规则应该是这样:
if(year%400==0||(year%4==0&&year%100!=0))
days = 29;
else
days = 28;
shitoucyz 2012-10-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

什么怎么改?讲清楚一点。
[/Quote]就是改的能够实现日历的功能....并且要国际化...
shitoucyz 2012-10-31
  • 打赏
  • 举报
回复
就是改的能够实现日历的功能....并且要国际化...
halfsuccess 2012-10-31
  • 打赏
  • 举报
回复
什么怎么改?讲清楚一点。

62,614

社区成员

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

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