java第一个测试点RE有没有大佬知道咋回事啊
查看原帖
java第一个测试点RE有没有大佬知道咋回事啊
1198742
Yi_Eins楼主2024/3/26 22:25
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //输入年份和月份
        int years = sc.nextInt();
        int months = sc.nextInt();
        String s = years + "-" + (months+1) + "-1";
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-M-d");
        LocalDate ld = LocalDate.parse(s,df);
        int day = 0;
        switch (months){
            case 1,3,5,7,8,10,12 -> {day = 31;}
            case 4,6,9,11 -> {day = 30;}
            case 2 -> {
                LocalDate ld2 = ld.minusDays(1);
                day = ld2.getDayOfMonth();
            }
            default -> day = -1;
        }
        System.out.println(day);
    }
}
2024/3/26 22:25
加载中...