求助java关于日历的代码
package classDemo01;
import java.text.DateFormatSymbols ;
import java.util.* ;
public class DateDemo01 {
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 indent = 0 ;
while(weekday != firstDayOfweek)
{
indent++ ;
d.add(Calendar.DAY_OF_MONTH,-1) ;
weekday = d.get(Calendar.DAY_OF_WEEK) ;
}
String[] weekdaynames = new DateFormatSymbols().getShortWeekdays() ;
do
{
System.out.printf("%4s",weekdaynames[weekday]) ;
d.add(Calendar.DAY_OF_MONTH,1) ;
weekday = d.get(Calendar.DAY_OF_WEEK) ;
}
while(weekday != firstDayOfweek) ;
System.out.println() ;
for(int i=1;i<=indent;i++){
System.out.print(" ") ;// i=0 看看可不可以!!!!!!!!!!!!!!!!!
}
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("*") ;
}else{
System.out.print(" ") ;
}
d.add(Calendar.DAY_OF_MONTH,1) ;
weekday = d.get(Calendar.DAY_OF_WEEK) ;
if(weekday == firstDayOfweek){
System.out.println() ;
}
}
while(d.get(Calendar.MONTH)==month) ;
if(weekday != firstDayOfweek){
System.out.println() ;
}
}
}
为什么结果变成这样了图片这样 没对齐~~~~ 麻烦各位大神了~~
------解决方案--------------------import java.text.DateFormatSymbols ;
import java.util.* ;
public class SSSS {
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 indent = 0 ;
while(weekday != firstDayOfweek)
{
indent++ ;
d.add(Calendar.DAY_OF_MONTH,-1) ;
weekday = d.get(Calendar.DAY_OF_WEEK) ;
}
String[] weekdaynames = new DateFormatSymbols().getShortWeekdays() ;
do
{
System.out.printf("%4s",weekdaynames[weekday]) ;
d.add(Calendar.DAY_OF_MONTH,1) ;
weekday = d.get(Calendar.DAY_OF_WEEK) ;
}
while(weekday != firstDayOfweek) ;
System.out.println() ;
for(int i=1;i<=indent;i++){
System.out.print(" ") ;// i=0 看看可不可以!!!!!!!!!!!!!!!!!
}
d.set(Calendar.DAY_OF_MONTH,1) ;
do
{
int day = d.get(Calendar.DAY_OF_MONTH) ;
System.out.printf("%5d",day) ;
if(day == today){
System.out.print("*") ;
}else{
System.out.print(" ") ;
}
d.add(Calendar.DAY_OF_MONTH,1) ;
weekday = d.get(Calendar.DAY_OF_WEEK) ;
if(weekday == firstDayOfweek){
System.out.println() ;
}
}
while(d.get(Calendar.MONTH)==month) ;
if(weekday != firstDayOfweek){
System.out.println() ;
}
}
}
我帮你解决了哦 有时间可以请教一下你吗 我的QQ976317873加我哦备注Java爱好者