import java.util.Scanner;
public class test {
public static void main(String[] args) {
System.out.println("请输入参数,多个参数以逗号分开:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String arr[] = str.split(",");
switch (arr.length) {// 根据数组的长度来决定掉用哪个方法
case 1:
System.out.println(arr[0] + "年是"
+ year(Integer.valueOf(arr[0]).intValue()));
break;
case 2:
System.out.println(arr[0]
+ "年"
+ arr[1]
+ "月有"
+ month(Integer.valueOf(arr[0]).intValue(), Integer
.valueOf(arr[1]).intValue()) + "天");
break;
case 3:
System.out.println(arr[0]
+ "年"
+ arr[1]
+ "月"
+ arr[2]
+ "日是星期"
+ day(Integer.valueOf(arr[0]).intValue(), Integer.valueOf(
arr[1]).intValue(), Integer.valueOf(arr[2])
.intValue()));
break;
default:
System.out.println("您输入的参数有误!");
}
}
public static String year(int y) {// 判断该年是不是闰年
String leap = (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) ? "闰年"
: "平年";
return leap;
}
public static int month(int y, int m) {// 计算指定年份的某个月有多少天
System.out.println(m);
int days = 0;
String leap = year(y);
if (m > 7) {
if (m % 2 == 0) {
days = 31;
} else {
days = 30;
}
} else {
if (m % 2 == 0) {
days = 31;
} else {
days = 30;
}
if (m == 2 && leap.equals("闰年")) {
days = 29;
} else if (m == 2 && leap.equals("平年")) {
days = 28;
}
}
return days;
}
public static String day(int y, int m, int d) {// 求出某年某月某日的这一天是星期几
if (m == 1 || m == 2) {
m += 12;
y--;
}
int week = d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400
+ 1;
week = week % 7;
String w = "日一二三四五六".substring(week, week + 1);
return w;
}
}
public class test {
public static void main(String[] args) {
System.out.println("请输入参数,多个参数以逗号分开:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String arr[] = str.split(",");
switch (arr.length) {// 根据数组的长度来决定掉用哪个方法
case 1:
System.out.println(arr[0] + "年是"
+ year(Integer.valueOf(arr[0]).intValue()));
break;
case 2:
System.out.println(arr[0]
+ "年"
+ arr[1]
+ "月有"
+ month(Integer.valueOf(arr[0]).intValue(), Integer
.valueOf(arr[1]).intValue()) + "天");
break;
case 3:
System.out.println(arr[0]
+ "年"
+ arr[1]
+ "月"
+ arr[2]
+ "日是星期"
+ day(Integer.valueOf(arr[0]).intValue(), Integer.valueOf(
arr[1]).intValue(), Integer.valueOf(arr[2])
.intValue()));
break;
default:
System.out.println("您输入的参数有误!");
}
}
public static String year(int y) {// 判断该年是不是闰年
String leap = (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) ? "闰年"
: "平年";
return leap;
}
public static int month(int y, int m) {// 计算指定年份的某个月有多少天
System.out.println(m);
int days = 0;
String leap = year(y);
if (m > 7) {
if (m % 2 == 0) {
days = 31;
} else {
days = 30;
}
} else {
if (m % 2 == 0) {
days = 31;
} else {
days = 30;
}
if (m == 2 && leap.equals("闰年")) {
days = 29;
} else if (m == 2 && leap.equals("平年")) {
days = 28;
}
}
return days;
}
public static String day(int y, int m, int d) {// 求出某年某月某日的这一天是星期几
if (m == 1 || m == 2) {
m += 12;
y--;
}
int week = d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400
+ 1;
week = week % 7;
String w = "日一二三四五六".substring(week, week + 1);
return w;
}
}