package com.day6;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
// 월별 날수를 배열에 저장
int months[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int y,m,nalsu,i,week,d;
String str[]= {"일","월","화","수","목","금","토"};
do {
System.out.print("년도?");
y=sc.nextInt();
}while(y<1);
do {
System.out.print("월?");
m=sc.nextInt();
}while(m<1&&m>12);
//윤년 먼저 계산
if (y%4 == 0 && y%100 != 0 || y%400 ==0)
months[1]=29;
do {
System.out.print("일?");
d=sc.nextInt();
}while(d<1&&d>months[m-1]);
//1년 1월1일부터 ~ 현재년의 전년도 12월 31일까지의 날수
//+ 2018년까지의 윤년 수
nalsu=(y-1)*365 + (y-1)/4 - (y-1)/100 + (y-1)/400;
for(i=0;i<m-1;i++) {
nalsu+=months[i];
}
nalsu += d; // d일 까지의 날수
//주의 수 (0 1 2 3 4 5 6)
week= nalsu%7; //1일때는 월요일 ,2일때는 화요일
System.out.printf("%d년 %d월 %d일은 %s 입니다",y,m,d,str[week]);
}
}
'Java' 카테고리의 다른 글
Java 설치하기 - JDK 설치, Eclipse 설치 (이대로만 따라하세요!) (0) | 2020.04.27 |
---|---|
NullPointException 이 나는 경우 (0) | 2020.02.22 |
추상클래스와 인터페이스 (0) | 2020.01.07 |
버전별 만년달력 (미완) (0) | 2019.11.13 |
별찍기 예제 (0) | 2019.11.13 |