华为4.18第二题输出结果都正确,为什么通过率0%?
请大家帮忙看看:未考虑N>400,但正常用例的结果是正确的,为什么最后println(1)都有通过率,println(num)却是0?
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int years = in.nextInt();
int weeks = in.nextInt();
in.close();
int num = 0;
while (years > 0){
int year = years + 1899;
int i = 1;
while (i <= 12){
Date date = Date.valueOf(year + "-" + String.valueOf(i) + "-13");
SimpleDateFormat formatter = new SimpleDateFormat("E");
String str = formatter.format(date);
//System.out.println(date);
//System.out.println(str);
int j = -1;
if (str.equals("星期一"))j = 1;
if (str.equals("星期二"))j = 2;
if (str.equals("星期三"))j = 3;
if (str.equals("星期四"))j = 4;
if (str.equals("星期五"))j = 5;
if (str.equals("星期六"))j = 6;
if (str.equals("星期日"))j = 0;
if(j == weeks) num++;
i++;
}
years = years - 1;
}
System.out.println(num);
}
}
#笔试题目##实习#import java.text.SimpleDateFormat;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int years = in.nextInt();
int weeks = in.nextInt();
in.close();
int num = 0;
while (years > 0){
int year = years + 1899;
int i = 1;
while (i <= 12){
Date date = Date.valueOf(year + "-" + String.valueOf(i) + "-13");
SimpleDateFormat formatter = new SimpleDateFormat("E");
String str = formatter.format(date);
//System.out.println(date);
//System.out.println(str);
int j = -1;
if (str.equals("星期一"))j = 1;
if (str.equals("星期二"))j = 2;
if (str.equals("星期三"))j = 3;
if (str.equals("星期四"))j = 4;
if (str.equals("星期五"))j = 5;
if (str.equals("星期六"))j = 6;
if (str.equals("星期日"))j = 0;
if(j == weeks) num++;
i++;
}
years = years - 1;
}
System.out.println(num);
}
}