主题:求救
我想编个日历大家看下错误最后的两个for循环有问题就是不知道错在哪?侠士救命!
import java.util.*;
public class Zuoye {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int days=0;
int sum=0;
Scanner s=new Scanner(System.in);
System.out.print("请输入年份:\n");
int year=s.nextInt();
System.out.print("请输入月份:\n");
int yue=s.nextInt();
if(year%4==0&&year%100!=0||year%400==0){
System.out.println(year+"\t是闰年");
}else{
System.out.println(year+"\t是平年");
}
switch(yue){
case 4:
case 6:
case 9:
case 11:
System.out.println(yue+"\t共30天");
days=30;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
System.out.println(yue+"\t共29天");
days=29;
}else{
System.out.println(yue+"\t共28天");
days=28;
}
break;
default:
System.out.println(yue+"\t共31天");
days=31;
}
for(int i=1900;i<year;i++){
if(i%4==0&&i%100!=0||i%400==0){
sum=sum+366;
}else{
sum=sum+365;
}
}
switch(yue){
case 4:
case 6:
case 9:
case 11:
sum=sum+30;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
sum=sum+29;
}else{
sum=sum+28;
}
break;
default:
sum=sum+31;
}
int xingqi=1+sum%7;
for(int i=0;i<7;i++){
System.out.print("星期"+i+"\t");
}
for(int nullNo=0;nullNo<xingqi;nullNo++){
System.out.print("\t");
}
for(int j=1;j<=days;j++){
if((j+sum)%7==1){
System.out.println();
}else{
System.out.print(j+"\t");
}
}
}
}
import java.util.*;
public class Zuoye {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int days=0;
int sum=0;
Scanner s=new Scanner(System.in);
System.out.print("请输入年份:\n");
int year=s.nextInt();
System.out.print("请输入月份:\n");
int yue=s.nextInt();
if(year%4==0&&year%100!=0||year%400==0){
System.out.println(year+"\t是闰年");
}else{
System.out.println(year+"\t是平年");
}
switch(yue){
case 4:
case 6:
case 9:
case 11:
System.out.println(yue+"\t共30天");
days=30;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
System.out.println(yue+"\t共29天");
days=29;
}else{
System.out.println(yue+"\t共28天");
days=28;
}
break;
default:
System.out.println(yue+"\t共31天");
days=31;
}
for(int i=1900;i<year;i++){
if(i%4==0&&i%100!=0||i%400==0){
sum=sum+366;
}else{
sum=sum+365;
}
}
switch(yue){
case 4:
case 6:
case 9:
case 11:
sum=sum+30;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
sum=sum+29;
}else{
sum=sum+28;
}
break;
default:
sum=sum+31;
}
int xingqi=1+sum%7;
for(int i=0;i<7;i++){
System.out.print("星期"+i+"\t");
}
for(int nullNo=0;nullNo<xingqi;nullNo++){
System.out.print("\t");
}
for(int j=1;j<=days;j++){
if((j+sum)%7==1){
System.out.println();
}else{
System.out.print(j+"\t");
}
}
}
}