问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图
package assignment;
import java.util.Scanner;
public class PrintCalendar {
public static void main (String args[]) {
Scanner in = new Scanner (System.in);
int year = in.nextInt();
int month = in.nextInt();
int sum = 0 , k = 0 ;
for(int i = 1 ; i < month - 1 ; i ++) {
if(i == 2) {
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ) {
sum =sum + 29;
}
else {
sum = sum+28;
}
}
else {
if(i == 4|| i == 6 || i == 9 || i == 11) {
sum = sum + 30;
}
else {
sum = sum + 31;
}
}
}
for(int a = 1900 ; a<= year -1 ; a ++) {
if(a%4 == 0 && a%100 != 0 || a%400 == 0) {
sum = sum + 356;
}
else {
sum = sum + 365;
}
}
sum = sum +1 ;
int wekday = sum % 7 ;
System.out.println("Mon\tTue\tWed\tThu\tFri\tSat\tSun");
for(int j = 1 ; j <= wekday ; j ++) {
System.out.println("\t");
}
if(year % 4== 0 && year % 100 != 0 || year % 400 == 0) {
if(month == 2) {
k = 29;
}
else if (month == 4 || month == 6 || month == 9 || month == 11) {
k = 30;
}
else {
k = 31;
}
}
else {
if(month == 2) {
k = 28;
}
else if(month == 4 || month == 6 || month == 9 || month == 11) {
k = 30 ;
}
else {
k = 31;
}
}
for(int i = 1 ; i <=k ; i++);
{
if(sum % 7 == 6) {
System.out.print(i+"\n");
}
else {
System.out.print(i + ' ');
}
}
System.out.println("\n");
}
}
运行结果及报错内容
我想要达到的结果
循环正常进行