public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()){
int y = in.nextInt(), m = in.nextInt();
if (m == 2){
if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)){
System.out.println("29");
} else {
System.out.println("28");
}
}
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12){
System.out.println("31");
} else if (m == 4 || m == 6 || m == 9 || m == 11) {
System.out.println("30");
}
}
} import java.util.Scanner;
import java.util.Arrays;
import java.util.List;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) { // 注意 while 处理多个 case
int year = in.nextInt();
String month = in.next();
String[] big = new String[] {"1", "3", "5", "7", "8", "10", "12"};
List<String> bigList = Arrays.asList(big);
// 2月
if ("2".equals(month)) {
//闰年
if ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ) {
System.out.println(29);
} else {
System.out.println(28);
}
//大月
} else if (bigList.contains(month)) {
System.out.println(31);
} else {
System.out.println(30);
}
}
}
} 我好蠢na
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int year = in.nextInt();
int month = in.nextInt();
// 判断是否闰年
boolean isRunNian = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(31);
break;
case 4:
case 6:
case 9:
case 11:
System.out.println(30);
break;
case 2:
System.out.println(isRunNian ? 29: 28);
}
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int year = in.nextInt();
int month = in.nextInt();
// 31天月份的正则表达式
String day31 = "[13578]|10$|12$";
// 30天月份的正则表达式
String day30 = "[469]|11$";
String strMonth = String.valueOf(month);
if(month == 2){
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
System.out.println(29);
}else{
System.out.println(28);
}
}else {
if(strMonth.matches(day31)){
System.out.println(31);
}
if(strMonth.matches(day30)){
System.out.println(30);
}
}
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int y = in.nextInt();
int m = in.nextInt();
if(y%4==0&&y%100!=0){
if(m==2){
System.out.println(29);
}
}else if(y%400==0){
if(m==2){
System.out.println(29);
}
}else if(m==2){
System.out.println(28);
}
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){
System.out.println(31);
}else if(m==4||m==6||m==9||m==11){
System.out.println(30);
}
}
}
} import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
int year = scanner.nextInt();
int month = scanner.nextInt();
if(month == 1 | month == 3 | month == 5 | month == 7 | month == 8 | month == 10 | month == 12){
System.out.println("31");
}else if(month == 4 | month == 6 | month == 9 | month == 11){
System.out.println("30");
}else if(month == 2){
if((year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0){
System.out.println("29");
}else{
System.out.println("28");
}
}
}
}
} import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int y = sc.nextInt();
int run = 0;
if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
System.out.println("31");
} else {
if (y == 2) {
if (n % 4 == 0 && n % 100 != 0) {
System.out.println("29");
} else if (n % 1000 == 0) {
System.out.println("29");
} else {
System.out.println("28");
}
} else {
System.out.println("30");
}
}
}
}
}
import java.util.*;
public class Main{
public static int getday(int y,int m){
int day=0;
if(m==1|m==3|m==5|m==7|m==8|m==10|m==12){
return day=31;
}
else if(m==4|m==6|m==9|m==11){
return day=30;
}
else if(m==2){
if(y%4==0&&y%100!=0|y%400==0){
return day=29;
}
else
return day=28;
}
return day;
}
public static void main(String args[]){
Scanner input=new Scanner(System.in);
while(input.hasNext()){
int year=input.nextInt();
int mon=input.nextInt();
System.out.println(getday(year,mon));
}
}
} import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
/**
* @Title: 获得月份天数
* @Remark: KiKi想获得某年某月有多少天,请帮他编程实现。输入年份和月份,计算这一年这个月有多少天。
* @Author: ijunfu
* @Version: 1.0.0
* @Date: 2022-03-19
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNextLine()) {
List<Integer> list = Arrays.stream(in.nextLine().split(" ")).map(x -> Integer.valueOf(x)).collect(Collectors.toList());
int year = list.get(0);
int month = list.get(1)-1;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println(day);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNextInt()) {
int year = scan.nextInt();
int month = scan.nextInt();
//判断月份
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println("31");
break;
case 2:
if (isLeapYear(year)) {
System.out.println("29");
} else {
System.out.println("28");
}
break;
default:
System.out.println("30");
break;
}
}
}
public static boolean isLeapYear(int year) {
if((year % 100 != 0 && year % 4 == 0)||(year %400 == 0)) {
return true;
} else {
return false;
}
}
} import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int year=sc.nextInt(); int month=sc.nextInt(); boolean flg=(year%4==0 && year%100!=0) || (year%400==0); String[] str1=new String[]{"1","3","5","7","8","10","12"}; String[] str2=new String[]{"4","6","9","11"}; if(flg && month==2){ System.out.println(29); }else if(flg && Arrays.asList(str1).contains(month+"")){ System.out.println(31); }else if(flg && Arrays.asList(str2).contains(month+"")){ System.out.println(30); }else if(!flg && month==2){ System.out.println(28); }else if(!flg && Arrays.asList(str1).contains(month+"")){ System.out.println(31); }else if(!flg && Arrays.asList(str2).contains(month+"")){ System.out.println(30); } } } }
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
Integer year = sc.nextInt();
Integer month = sc.nextInt();
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println("31");
break;
case 4:
case 6:
case 9:
case 11:
System.out.println("30");
break;
case 2:
if(year%4==0){ System.out.println("29");}
else {System.out.println("28");}
break;
}
}
}
}不要忘记break;就行
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int year = sc.nextInt();
int month = sc.nextInt();
switch (month){
case 2:
if ((year%100==0 && year%400!=0) || year%4!=0){
System.out.println(28);
}else {
System.out.println(29);
};
break;
case 4:System.out.println(30);break;
case 6:System.out.println(30);break;
case 9:System.out.println(30);break;
case 11:System.out.println(30);break;
default: System.out.println(31);
}
}
}
}