import java.text.DateFormatSymbols; public static void main(String[] args) String[] weekdayNAME = new DateFormatSymbols().getShortMonths(); weekday = d.get(Calendar.DAY_OF_WEEK); System.out.println(); d.set(Calendar.DAY_OF_MONTH, 1); if(weekday != d.getFirstDayOfWeek()) System.out.println(); |
|
import java.text.DateFormatSymbols; import java.util.*; public class Calendar { 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); int firstdayofweek = d.getFirstDayOfWeek(); int indents = 0; do { indents++; d.add(DAY_OF_MONTH, 1); weekday = d.get(Calendar.DAY_OF_WEEK); } while(weekday!=d.getFirstDayOfWeek()); String[] weekdayNAME = new DateFormatSymbols().getShortMonths(); do { System.out.printf("%4s",weekdayNAME[weekday]); d.add(Calendar.DAY_OF_MONTH, 1); weekday = d.get(Calendar.DAY_OF_WEEK); } while(weekday!=d.getFirstDayOfWeek()); weekday = d.get(Calendar.DAY_OF_WEEK); System.out.println(); for(int i = 0;i < indents;i++) System.out.print(" "); d.set(Calendar.DAY_OF_MONTH, 1); do { int day = d.get(Calendar.DAY_OF_MONTH); System.out.printf("%3d",day); if(day == today) System.out.print("*"); d.add(Calendar.DAY_OF_MONTH, 1); weekday = d.get(Calendar.DAY_OF_WEEK); if(weekday == d.getFirstDayOfWeek()) System.out.println(); } while(month == d.get(Calendar.MONTH)); if(weekday != d.getFirstDayOfWeek()) System.out.println(); } } 刚才没发好,重新发一下,这里面的Calendar.DAY_OF_MONTH Calendar.DAY_OF_WEEK之类的提示无法解析 |
|
10分 |
import java.util.Calendar;
|
30分 |
你这是自己定义了一个类叫Calendar?
public class Calendar { public static void main(String[] args) { .... Calendar.DAY_OF_WEEK 然后你自己又用这个类的属性 DAY_OF_WEEK 他这些属性怎么会存在? java.util.Calendar.DAY_OF_WEEK才行吧? |
太感谢了,这么个小问题啊,刚学java没注意到这个类名的问题,当时就随便定义了个名字,没想到正好冲突了
|