자바 기초: 날짜 출력

kevinkim2586·2020년 3월 16일
0

Java

목록 보기
3/6
post-thumbnail

public class Date {
	int year;
	int month;
	int day;
	
	public Date(int year, int month, int day) {
		this.year = year;
		this.month = month;
		this.day = day;
	}
	public void print1() {
		System.out.println(year+"."+month+"."+day);
	}
	public void print2() {
		switch(month) {
		case 1 : System.out.print("January"); break;
		case 2 : System.out.print("February"); break;
		case 3 : System.out.print("March"); break;
		case 4 : System.out.print("April"); break;
		case 5 : System.out.print("May"); break;
		case 6 : System.out.print("June"); break;
		case 7 : System.out.print("July"); break;
		case 8 : System.out.print("August"); break;
		case 9 : System.out.print("September"); break;
		case 10 :System.out.print("October"); break;
		case 11 :System.out.print("November"); break;
		case 12 :System.out.print("December"); break;
		}
		System.out.println(" "+day+", "+year);
	}

	public static void main(String[] args) {
		Date obj = new Date(2012,9,5);
		obj.print1();
		obj.print2();
	}

}
profile
공개적으로 학습하고자 만든 블로그

0개의 댓글