标签:blog http java ar for 2014 sp log on
import java.util.Scanner;
/*
* 计算2013年的某月某日是当年的第多少天?
* 是星期几?已知2013年元旦是星期二。
*/
public class Test2 {
public static void main(String[] args) {
int month, day;
int monthDay = 0;
boolean n = true;
Scanner input = new Scanner(System.in);
System.out.println("请输入2013年的某月某日:");
month = input.nextInt();
day = input.nextInt();
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
|| month == 10 || month == 12) {
if (day > 0 && day <= 31) {
monthDay = monthDay + day;
} else {
n = false;
}
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
if (day > 0 && day <= 30) {
monthDay = monthDay + day;
} else {
n = false;
}
} else if (month == 2) {
if (day > 0 && day <= 28) {
monthDay = monthDay + day;
} else {
n = false;
}
} else {
n = false;
}
for (int i = 0; i < month; i++) {
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10
|| i == 12) {
monthDay = monthDay + 31;
} else if (i == 4 || i == 6 || i == 9 || i == 11) {
monthDay = monthDay + 30;
} else if (i == 2) {
monthDay = monthDay + 28;
}
}
if (n) {
System.out.println("2013年的" + month + "月" + day + "日是当年的第"
+ monthDay + "天");
switch (monthDay % 7) {
case 0: {
System.out.println("是星期一");
break;
}
case 1: {
System.out.println("是星期二");
break;
}
case 2: {
System.out.println("是星期三");
break;
}
case 3: {
System.out.println("是星期四");
break;
}
case 4: {
System.out.println("是星期五");
break;
}
case 5: {
System.out.println("是星期六");
break;
}
case 6: {
System.out.println("是星期天");
break;
}
default:
break;
}
} else {
System.out.println("输入的日期不符合条件");
}
}
}
标签:blog http java ar for 2014 sp log on
原文地址:http://www.cnblogs.com/fantasy12436109/p/3970917.html