Topic: 大哥们给我看看 (打印 Calendar) |
Print this page |
1.大哥们给我看看 (打印 Calendar) | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-20 20:24 { 请尽量用准确的文字描述作为标题 请考虑使用原有的话题 } 现在改成这样 但是输出来的格式和预计的不一样 import java.util.*; public class CalendarTest { public static void main(String[] args) { GregorianCalendar d= new GregorianCalendar(); int today=d.get(Calendar.DAY_OF_MONTH); int month =d.get(Calendar.MONTH); d.set(Calendar.DAY_OF_MONTH,1); int weekday = d.get(Calendar.DAY_OF_WEEK); System.out.println(" Sun Mon The Wed Thu Fri Set"); for(int i=Calendar.SUNDAY;i<weekday;i++) System.out.print(" "); do { int day = d.get(Calendar.DAY_OF_MONTH); if (day<10) { System.out.print(" "); } System.out.print(day); if (day==today) { System.out.print("* "); } else System.out.print(" "); if (weekday == Calendar.SATURDAY) { System.out.println(); } d.add(Calendar.DAY_OF_WEEK,1); } while (d.get(Calendar.MONTH)==month); if (weekday!=Calendar.SUNDAY) { System.out.println(); } } }; 出错了 |
2.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-20 20:47 出什么错? |
3.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-20 21:36 编译不过啊 大哥们给我看看那里错了好吗 |
4.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-20 21:44 编译 出什么错? |
5.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: helloworld Posted on: 2004-10-20 22:00 1 , 少了main方法 2 , d.add(Calendar.DAY_OF_WEEK); 少一只int |
6.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-20 22:06 你查差你的书,看看一个class是怎么定义的,然后对照你的代码进行修改,比如:
|
7.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: helloworld Posted on: 2004-10-20 22:17 看来是想打印一个这个东东. |
8.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-20 22:18 你非要我说明白了:你写的根本不是一个Java类。一个java类不是你写的那个样子。 你用: public static void main(String[] args){ } 把你的代码部分全部放进这个{}中试试。 |
9.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-20 22:21 另:把上面的那个东东放进public class CalendarTest { } 中 |
10.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: kulatasana Posted on: 2004-10-20 23:05 楼主的代码中没有main()方法,肯定通不过的. |
11.Re:大哥们给我看看 [Re: helloworld] | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-20 23:38 helloworld wrote: 对了 这是core java2 上的例子 |
12.Re:大哥们给我看看 [Re: pgty] | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-20 23:53 好了 应该是这样的 不过输出来的格式不对哦 import java.util.*; public class CalendarTest { public static void main(String[] args) { GregorianCalendar d= new GregorianCalendar(); int today=d.get(Calendar.DAY_OF_MONTH); int month =d.get(Calendar.MONTH); d.set(Calendar.DAY_OF_MONTH,1); int weekday = d.get(Calendar.DAY_OF_WEEK); System.out.println(" Sun Mon The Wed Thu Fri Set"); for(int i=Calendar.SUNDAY;i<weekday;i++) System.out.print(" "); do { int day = d.get(Calendar.DAY_OF_MONTH); if (day<10) { System.out.print(" "); } System.out.print(day); if (day==today) { System.out.print("* "); } else System.out.print(" "); if (weekday == Calendar.SATURDAY) { System.out.println(); } d.add(Calendar.DAY_OF_WEEK,1); } while (d.get(Calendar.MONTH)==month); if (weekday!=Calendar.SUNDAY) { System.out.println(); } } }; |
13.Re:大哥们给我看看 () [Re: pgty] | Copy to clipboard |
Posted by: why Posted on: 2004-10-21 08:25 while (d.get(Calendar.MONTH)==month); // problem here if (weekday!=Calendar.SUNDAY) { System.out.println(); } } }; // unnecessary |
14.Re:大哥们给我看看 () [Re: pgty] | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-21 13:30 while (d.get(Calendar.MONTH)==month); // the loop exits when d is day 1 of the next month if (weekday!=Calendar.SUNDAY) //print final end of line if necessary { System.out.println(); } } }; // unnecessary |
15.Re:大哥们给我看看 () [Re: pgty] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-21 18:49 pgty : 你的代码可以当成教科书中的错误典型例子了。 |
16.Re:大哥们给我看看 () [Re: pgty] | Copy to clipboard |
Posted by: why Posted on: 2004-10-21 19:19 oops, I didn't read carefully...
|
17.Re:大哥们给我看看 (打印 Calendar) [Re: pgty] | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-21 22:48 谢谢总版和各位 |
18.Re:大哥们给我看看 () [Re: kavinwang] | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-21 22:49 kavinwang wrote: 怎么说呢? |
19.Re:大哥们给我看看 (打印 Calendar) [Re: pgty] | Copy to clipboard |
Posted by: pgty Posted on: 2004-10-21 23:07 我那段代码是不是算法错了? |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |