【20171002】Java每日一練
阿新 • • 發佈:2019-01-23
package c2;
import java.util.Scanner;
public class C2_03 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int month;
int mmonth;
int year;
int date;
int day;
long total = 0;
System.out.println("請輸入年份:");
Scanner sc3 = new Scanner(System.in);
year = sc3.nextInt();
System.out.println("請輸入月份:");
Scanner sc = new Scanner(System.in);
month = sc.nextInt();
System.out.println("請輸入日期:");
Scanner sc2 = new Scanner(System.in);
date = sc2.nextInt();
for(int j = 1900 ; j <= year ; j++)
{
if(((j % 100 != 0) && (j % 4 == 0)) || (j % 400) == 0){
total+=1;
}
}
total = total +(year - 1900) * 365 + date;
for(mmonth = month -1;mmonth >=1;mmonth --){
if(mmonth == 1)
{
total += 31 ;continue;
}
if(mmonth <= 2){
if(((year % 100 != 0) && (year % 4 == 0)) || (year % 400) == 0){
total +=29;continue;
}
else{
total += 28;continue;
}
}
if(mmonth <= 3)
{
total += 31;continue;
}
if(mmonth <= 4)
{
total += 30;continue;
}
if(mmonth <= 5)
{
total += 31;continue;
}
if(mmonth <= 6)
{
total += 30;continue;
}
if(mmonth <= 7)
{
total += 31;continue;
}
if(mmonth <= 8)
{
total += 31;continue;
}
if(mmonth <= 9)
{
total += 30;continue;
}
if(mmonth <= 10)
{
total += 31;continue;
}
if(mmonth <= 11 )
{
total += 30;continue;
}
}
System.out.println("這一天是第" + total + "天");
day = (int)(total % 7);
//System.out.println("今天是星期" + day);
switch(day)
{
case 1:
System.out.println("這一天是星期1。");
break;
case 2:
System.out.println("這一天是星期2。");
break;
case 3:
System.out.println("這一天是星期3。");
break;
case 4:
System.out.println("這一天是星期4。");
break;
case 5:
System.out.println("這一天是星期5。");
break;
case 6:
System.out.println("這一天是星期6。");
break;
default:
System.out.println("這一天是星期7。");
}
}
}