๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป/JAVA

[Java] 6์ผ์ฐจ : ๋ฐฐ์—ด

by ๋”ฐ๊ถˆ 2024. 2. 21.

๋ฐฐ์—ด(array)์ด๋ž€?

ํฌ๊ธฐ์™€ ์„ฑ๊ฒฉ์ด ๊ฐ™์€ ์ผ๋ จ์˜ ์›์†Œ๋“ค์ด ๋ชจ์—ฌ ๊ณต๋™์˜ ์ง‘ํ•ฉ ๊ตฌ์กฐ๋ฅผ ๊ฐ–๋Š” ์ž๋ฃŒ์˜ ์ง‘ํ•ฉ์ฒด
๋™์งˆ์ ์ธ ์„ฑ๊ฒฉ์„ ๊ฐ€์ง„ ์ž๋ฃŒ๋“ค์— ๊ฐœ๋ณ„์ ์œผ๋กœ ์ž๋ฃŒํ˜•์„ ๋ถ€์—ฌํ•˜์ง€ ์•Š๊ณ 
ํ•˜๋‚˜์˜ ์ด๋ฆ„์„ ๊ฐ€์ง€๊ณ  ์ฒ˜๋ฆฌํ•  ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉ

๋™์ผํ•œ ํƒ€์ž…์˜ ์—ฌ๋Ÿฌ ๋ณ€์ˆ˜๋“ค์„ ํ•˜๋‚˜์˜ ๋ฌถ์Œ์œผ๋กœ ๋‹ค๋ฃฌ๋‹ค
๊ฐ ์š”์†Œ๋Š” ๋ฉ”๋ชจ๋ฆฌ์ƒ์— ์—ฐ์†์ ์œผ๋กœ ์ €์žฅ
๋ฐฐ์—ด์˜ ์ด๋ฆ„ (์ฐธ์กฐํ˜• ๋ณ€์ˆ˜, ๋ ˆํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜)์€ ์—ฐ์†๋œ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์—
์ €์žฅ๋œ ๊ฐ’์„ ์ฐธ์กฐํ•˜๊ธฐ ์œ„ํ•œ ์ฐธ์กฐ ๊ฐ’(ํฌ์ธํ„ฐ)์„ ๊ฐ–๋Š”๋‹ค

์ฒ˜์Œ ์„ค์ •ํ•œ ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝ ํ•  ์ˆ˜ ์—†๋‹ค.

 

 

๋ฐฐ์—ด ์„ ์–ธ

์ž๋ฃŒํ˜•(ํƒ€์ž…) ๋˜๋Š” ๋ฐฐ์—ด๋ช…(๋ณ€์ˆ˜) ๋’ค์— ๋Œ€๊ด„ํ˜ธ ([])๋ฅผ ๋ถ™์—ฌ ๋ฐฐ์—ด ์„ ์–ธ

 

๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น

๋ฐฐ์—ด์€ ์„ ์–ธ ํ›„ ์—ฐ์†์ ์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ์ƒ์— ๊ฐ’์„ ์ €์žฅํ•  ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์„  new  ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ ํ• ๋‹น

ํ• ๋‹น ์‹œ ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋Š” intํ˜•์„ ์‚ฌ์šฉํ•œ๋‹ค. 

 

 

 

 

new ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹น ํ•œ ๊ฒฝ์šฐ ํƒ€์ž…์ด ์ˆซ์ž ํ˜•์ธ ๊ฒฝ์šฐ๋Š” 0,

๊ฐ์ฒด๋Š” null๋กœ ์ดˆ๊ธฐํ™”๊ฐ€ ์ž๋™์œผ๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค.

 

 

 

 

 

length ํ•„๋“œ

๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋Š” length ๋ผ๋Š” ํ•„๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ํ™•์ธ

 

 

 

 

 

Ex01. ๋ฐฐ์—ด ๊ฐ’ ์ถœ๋ ฅํ•˜๊ธฐ 

 

package ch05.unit01;

public class Ex01_Array {

	public static void main(String[] args) {
		// ๋ฐฐ์—ด ์„ ์–ธ ๋ฐ ๊ฐ’ ํ• ๋‹น
		int []a; // ๋ฐฐ์—ด ์„ ์–ธ
		a = new int[5]; // ๋ฉ”๋ชจ๋ฆฌํ• ๋‹น(5๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ์ €์žฅํ• ์ˆ˜ ์žˆ๋Š” ์ •์ˆ˜ํ˜• ๋ฐฐ์—ด)
		
		// int []a = new int[5]; // ๋ฐฐ์—ด ์„ ์–ธ๊ณผ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น์„ ํ•œ๋ฒˆ์—
		
		// System.out.println( a[0] ); // 0 
		//	๋ฐฐ์—ด์„ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น๊ณผ ๋™์‹œ์— ์ •์ˆ˜ํ˜• ๋ฐฐ์—ด์€ 0์œผ๋กœ ์ดˆ๊ธฐํ™”
		
		// ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ์— ๊ฐ’ ํ• ๋‹น
		a[0] = 1; a[1] = 3; a[2] = 5; a[3] = 7; a[4] = 9;
		// a[5] = 11; // ๋Ÿฐํƒ€์ž„ ์˜ค๋ฅ˜. ArrayIndexOutOfBoundsException
			// ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ฒจ์ž๋Š” 0~๋ฐฐ์—ด๊ธธ์ด-1
		
		// length ํ•„๋“œ : ๋ฐฐ์—ด์˜ ์š”์†Œ์˜ ๊ฐœ์ˆ˜ ๋ฐ˜ํ™˜
		int s = 0;
		for(int i=0; i<a.length; i++) {
			s += a[i];
		}
		System.out.println("๊ฒฐ๊ณผ : " + s);
	}

}

 

 

 

 

ํ–ฅ์ƒ๋œ for๋ฌธ




Ex02. ๋ฐฐ์—ด 

 

package ch04.unit06;

public class Ex02_Array {

	public static void main(String[] args) {
		int[] a = new int [5];
		a[0] = 90; a[1] = 80; a[3]=85; a[4]=90;
		
		int tot,ave;
		tot=0;
		
		for(int n:a) { //for(์ž๋ฃŒํ˜• ๋ณ€์ˆ˜ : ์ปฌ๋ ‰์…˜ํƒ€์ž…๋ณ€์ˆ˜) 
			tot +=n;			
		}
		ave = tot / a.length;
		System.out.println("์ด์  : "+tot);
		System.out.println("ํ‰๊ท  : "+ ave);
	}
}

 

 

 

Ex03.๋ฐฐ์—ด ์ถœ๋ ฅ

 

package ch04.unit06;

public class Ex03 {

	public static void main(String[] args) {
		// ๋ฐฐ์—ด์€ ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝ ํ•  ์ˆ˜ ์—†๋‹ค.
		// ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด ์ด์ „ ๋ฐฐ์—ด์€ ์œ„์น˜๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์—†์–ด
		// ์ด์ „ ๋ฐฐ์—ด์€ ๊ฐ€๋น„์ง€์ปฌ๋ ‰ํ„ฐ์˜ ๋Œ€์ƒ์ด ๋˜๋ฉฐ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์ด ๋งŒ๋“ค์–ด ์ง„๋‹ค
		
		int [] a = new int [3];
		a[0] = 10; a[1]= 20; a[2]=30;
		System.out.println("๋ฐฐ์—ด์„ ์„ ์–ธํ•˜๊ณ  ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น๊ณผ ๊ฐ’ ํ• ๋‹นํ›„ ...");
		for(int n:a) {
			System.out.println(n+" ");
		}
		
		System.out.println("\n๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝํ•œ ๊ฒฝ์šฐ...");
		
		a = new int[5]; // ๋‹ค์‹œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹น ๋ฐ›์œผ๋ฉด, ์ด์ „ ๋ฐฐ์—ด์€ garbage collector ๋Œ€์ƒ
		
		for(int n:a) {
			System.out.println(n+" "); // 0 0 0 0 0					
	}
}
}

 

 

 

Ex04. ๋ฐฐ์—ด ํ• ๋‹น

package ch04.unit06;

public class Ex04 {

	public static void main(String[] args) {
		// ๋ฐฐ์—ด์€ ์ฐธ์กฐํ˜•์ด๋‹ค
		
		// ์ผ๋ฐ˜ ๋ณ€์ˆ˜		
		int x = 10;
		int y = x;
		y+=20;
		System.out.println(x+","+y); // 10,30

		// ๋ฐฐ์—ด
		int []a = new int[3];
		a[0] = 10; a[1] = 20; a[2] = 30;
		
		System.out.println("์ดˆ๊ธฐ a ๋ฐฐ์—ด...");
		for(int n:a) {
			System.out.println(n+" ");
		}
		System.out.println();
		
		int []b = a; // ํ•˜๋‚˜์˜ ๋ฐฐ์—ด ๊ณต์œ 
		b[1] = 200;
		System.out.println("a ๋ฐฐ์—ด...");
		for(int n : a) {
			System.out.println(n+" ");
		}
		System.out.println();
		System.out.println("b ๋ฐฐ์—ด...");
		for(int n : b) {
			System.out.println(n+" ");
	}
	 System.out.println();
}
}

 

 

 

Ex05. ์ด๋ฆ„, ์ ์ˆ˜๋ฅผ ๋ฐ›์•„์„œ ํŽธ์ฐจ,์ดํ•ฉ,ํ‰๊ท  ๊ตฌํ•˜๊ธฐ
package ch04.unit06;

import java.util.Scanner;

public class Ex05 {

	public static void main(String[] args) {
		// 5๋ช…์˜ ์ด๋ฆ„๊ณผ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„ ํŽธ์ฐจ (์ˆ˜-ํ‰๊ท )์„ ๊ณ„์‚ฐํ•˜์—ฌ ์ด๋ฆ„, ์ ์ˆ˜, ํŽธ์ฐจ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ 
		// ๋งˆ์ง€๋ง‰์— ์ „์ฒด ์ด์ , ํ‰๊ท  ์ถœ๋ ฅ
		
		Scanner sc = new Scanner(System.in);
		
		String []name = new String[5];
		int []score = new int[5];
		int tot = 0;
		double ave, s;
		
		for(int i=0; i<name.length; i++) {
			System.out.println((i+1)+" ๋ฒˆ์งธ ์ด๋ฆ„? ");
			name[i] = sc.next();
			System.out.print("     ์ ์ˆ˜ ?");
			score[i] = sc.nextInt();
			
			tot += score[i];
		}
		ave = (double)tot / score.length;
				
				System.out.println("์ด๋ฆ„\t์ ์ˆ˜\tํŽธ์ฐจ");
				System.out.println("------------------");
				
				for(int i=0; i<name.length; i++) {
					s = score[i] -ave;
					System.out.println(name[i]+"\t"+score[i]+"\t"+s);
				}
				System.out.println("------------------");
				System.out.println("์ดํ•ฉ : "+ tot);
				System.out.println("------------------");
				System.out.println("ํ‰๊ท  : "+ ave);
				
		sc.close();
		
	}

}

 

 

 

Ex06. 1~ 100์‚ฌ์ด ์„œ๋กœ ๋‹ค๋ฅธ ๋‚œ์ˆ˜ 10๊ฐœ๋ฅผ ์ถœ๋ ฅํ•˜๊ธฐ

 

package ch04.unit06;

public class Ex06 {

	public static void main(String[] args) {
		// 1~100์‚ฌ์ด์˜ ์ˆ˜์ค‘ ์„œ๋กœ ๋‹ค๋ฅธ ๋‚œ์ˆ˜ 10๊ฐœ๋ฅผ ์ถœ๋ ฅํ•˜๊ธฐ
		/*
		int n ; 
		
		for(int i=1; i<=10; i++) {
		n = (int)(Math.random()*100)+1;
		System.out.print(n+" ");
	}
		System.out.println();
		*/
		int[]n = new int [10];
		for(int i = 0; i<n.length; i++) {
			n[i] = (int)(Math.random()*100)+1;
			
			// ๋™์ผํ•œ ๋‚œ์ˆ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด
			for(int j=0; j<i; j++) {
				if(n[i]==n[j]) {
					i--;
					break;
				}
			}		
		}
		for(int a:n) {
			System.out.println(a+ " ");
		}
		System.out.println();
}
}

๋žœ๋คํ•˜๊ฒŒ ๋‚˜์˜ด

 

 

๋ฐฐ์—ด์˜ ์ดˆ๊ธฐํ™”
์„ ์™€ ๋™์‹œ์— ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น๊ณผ ์ดˆ๊ธฐํ™” ๊ฐ€๋Šฅ
int[]arr = new int[]{10,20,30,40,50}
 or
int[]arr;
arr=new int []{,10,20,30,40,50};


 

Ex07. ๋ฐฐ์—ด ์ดˆ๊ธฐํ™”
package ch04.unit06;

public class Ex07 {

	public static void main(String[] args) {
		// ๋ฐฐ์—ด ์ดˆ๊ธฐํ™”
		/*
		 - ๋ฐฐ์—ด ์„ ์–ธ๊ณผ ๋™์‹œ์— ์ดˆ๊ธฐํ™”
		 	: ์ดˆ๊ธฐํ™” ํ•  ๋•Œ ์ดˆ๊ธฐ๊ฐ’์˜ ๊ฐฏ์ˆ˜๊ฐ€ ๋ฐฐ์—ด์˜ ํฌ๊ธฐ
		 	: ์ดˆ๊ธฐํ™” ํ• ๋•Œ  new int[]๋ฅผ new int[5]์ฒ˜๋Ÿผ ์š”์†Œ์˜ ํฌ๊ธฐ ์ง€์ • ๋ถˆ๊ฐ€
		 */
		int[] a= new int[] {2,4,6,8,10};
		// int [] a = {2,4,6,8,10}; 
		// ์„ ์–ธ๊ณผ ๋™์‹œ์— ์ดˆ๊ธฐํ™” ํ•  ๊ฒฝ์šฐ์—๋Š” new int[] ์ƒ๋žต ๊ฐ€๋Šฅ
		/*
		 int [] x ;
		 x = {1,3,5,7,9};; // ์ปดํŒŒ์ผ ์˜ค๋ฅ˜
		 x = new int[] {,1,3,5,7,9};
		 */
		System.out.println("๋ฐฐ์—ด ์š”์†Œ์˜ ๊ฐœ์ˆ˜ : "+ a.length);
		
		int tot = 0;
		for(int n : a) {
			tot += n;
		}
		System.out.println("๊ฒฐ๊ณผ:"+tot);
	}

}

 

Ex08. ์ง€ํ ๊ฐฏ์ˆ˜ ๊ตฌํ•˜๊ธฐ
package ch04.unit06;

public class Ex08 {

	public static void main(String[] args) {
		// 4320์›์„ ์ง€๋ถˆํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ 1000, 500,100,50,10์›
			// ์ง€ํ ๋˜๋Š” ๋™์ „์˜ ๊ฐœ์ˆ˜
			
		int[]unit = new int[] {1000,500,100,50,10};
		
		int money = 4320;
		System.out.println("๊ธˆ์•ก : "+money);
		System.out.println("ํ™”ํ\t๊ฐœ์ˆ˜");
		for(int n : unit) {
				System.out.println(n+"์›\t"+(money/n));
				money %=n;
		}			
	}
}

 

 

 

Quiz01. ๋ฐฐ์—ด๋กœ ๋  ๊ตฌํ•˜๊ธฐ

- ์ž…๋ ฅํ•œ ๋…„๋„๊ฐ€ 1900๋ณด๋‹ค ์ ์œผ๋ฉด ๋‹ค์‹œ ์ž…๋ ฅ

 

๋  ์ฅ ์†Œ ๋ฒ” ํ† ๋ผ ์šฉ ๋ฑ€ ๋ง ์–‘ ์›์ˆญ์ด ๋‹ญ ๊ฐœ ๋ผ์ง€
์—ฐ๋„ 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031

 

package ch04.unit06;

import java.util.Scanner;

public class Quiz01 {

	public static void main(String[] args) {
		// ๋  ๊ตฌํ•˜๊ธฐ 
		Scanner sc = new Scanner(System .in);
		String[]t = new String[] {"์›์ˆญ์ด","๋‹ญ","๊ฐœ","๋ผ์ง€","์ฅ","์†Œ","๋ฒ”","ํ† ๋ผ","์šฉ","๋ฑ€","์–‘"};
		
		int y ;
		do {
			System.out.print("๋…„๋„ ?");
			y = sc.nextInt();
		}while(y<1900);
		System.out.printf("%d๋…„๋„์˜ ํ•ด๋Š” %s๋ ์˜ ํ•ด์ž…๋‹ˆ๋‹ค.\n",y,t[y%12]);
	
		sc.close();
	}
}

 

 

 

Quiz02. 5๊ฐœ์˜ ์ ์ˆ˜(0~10)๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„ ์ตœ๋Œ€์ ์ˆ˜์™€ ์ตœ์†Œ์ ์ˆ˜๋ฅผ ๋บ€ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ

- ์ž…๋ ฅํ•œ ์ ์ˆ˜๊ฐ€ 0~10 ์‚ฌ์ด์˜ ์ ์ˆ˜๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ๋‹ค์‹œ ์ž…๋ ฅ

- ์ž…๋ ฅ ๋ฐ›์€ ์ ์ˆ˜๋Š” ๋ฐฐ์—ด์— ์ €์žฅ

- ์ทจ๋“์ ์ˆ˜ = ์ „์ฒด์ ์ˆ˜์˜ํ•ฉ - ์ตœ๋Œ€์ ์ˆ˜ - ์ตœ์†Œ์ ์ˆ˜

 

package ch05.unit01;

import java.util.Scanner;

public class Quiz02 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int []num = new int[5];
		
		for(int i=0; i<num.length; i++) {
			do {
				System.out.println((i+1)+"๋ฒˆ์งธ ์ ์ˆ˜ : ");
				num[i] = sc.nextInt();
			} while(num[i] < 0 || num[i] > 10);
			
		}
		
		// ์ตœ๋Œ€๊ฐ’, ์ตœ์†Œ๊ฐ’ ๊ตฌํ•˜๊ธฐ
		int max, min;
		
		/*
		max = 0; min = 10; // ๊ฐ€์žฅ ์ž‘์€๊ฐ’๊ณผ ํฐ๊ฐ’์„ ์ดˆ๊ธฐ์น˜๋กœ
		for(int i=0; i<num.length; i++) {
			if(max < num[i]) {
				max = num[i];
			} 
			if(min > num[i]) {
				min = num[i];
			}
		}
		*/

		max = min = num[0]; // ์ฒ˜์Œ๊ฐ’์„ ์ดˆ๊ธฐ์น˜
		for(int i=1; i<num.length; i++) {
			if(max < num[i]) {
				max = num[i];
			} else if(min > num[i]) {
				min = num[i];
			}
		}
		
		// ์ž…๋ ฅ ๋ฐ›์€ ์ „์ฒด ์ ์ˆ˜ ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅ
		int tot =0;
		System.out.print("์ „์ฒด ์ ์ˆ˜ ๋ฆฌ์ŠคํŠธ : ");
		for(int n : num) {
			tot += n;
			System.out.print(n + " ");
		}
		System.out.println();
		
		// ์ทจ๋“์ ์ˆ˜ ์ถœ๋ ฅ
		System.out.println("์ทจ๋“ ์ ์ˆ˜ : " + (tot-max-min));
		
		sc.close();
	}

}

 

 

 

 

 

Quiz04. ๋‹ฌ๋ ฅ ์ถ”์ถœํ•˜๊ธฐ

 

package ch05.unit01;

import java.util.Scanner;

public class Quiz04 {

	public static void main(String[] args) {
		/*
		  - ๋…„๋„๊ฐ€ 4์˜๋ฐฐ์ˆ˜์ด๊ณ  100์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹ˆ๊ฑฐ๋‚˜ 400์˜ ๋ฐฐ์ˆ˜์ด๋ฉด 
		    ์œค๋…„์œผ๋กœ 2์›”์ด 29์ผ์ด๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด 2์›”์€ 28์ผ
		  - 1๋…„ 1์›” 1์ผ : ์›”์š”์ผ
		*/
		
		Scanner sc = new Scanner(System.in);
		int [] days = new int[] {31,28,31,30,31,30,31,31,30,31,30,31};
		int y, m, tot, w;
		
		do {
			System.out.print("๋…„๋„ ? ");
			y = sc.nextInt();
		} while(y < 1900);
		
		do {
			System.out.print("์›” ? ");
			m = sc.nextInt();
		} while(m < 1 || m > 12);
		
		// y๋…„๋„์˜ 2์›”์˜ ๋งˆ์ง€๋ง‰ ๋‚ ์งœ
		days[1] = y%4==0&&y%100!=0 || y%400==0 ? 29 : 28;
		
		// 2024๋…„ 3์›” 
		// 1.1.1์ผ ~ 2024๋…„๋„ 3์›” 1์ผ๊นŒ์ง€ ์ „์ฒด ์ผ์ˆ˜
		// ์ „์ฒด์ผ์ˆ˜ = (y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400;
		// ์ „์ฒด์ผ์ˆ˜ += 1์›” + 2์›”(m-1) + 1
		
		tot = (y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400;
		for(int i=0; i<m-1; i++) {
			tot += days[i];
		}
		tot++;
		
		w = tot%7; // 1์ผ์˜ ์š”์ผ(0:์ผ,.. ,6:ํ† ) 
		
		System.out.printf("\n\t%d๋…„ %d์›”\n", y, m);
		System.out.println("   ์ผ   ์›”  ํ™”  ์ˆ˜   ๋ชฉ  ๊ธˆ  ํ† ");
		System.out.println("------------------------------");
		// 1์ผ ์•ž ๊ณต๋ฐฑ์ฒ˜๋ฆฌ
		for(int i=0; i<w; i++) {
			System.out.print("    ");
		}
		
		for(int i=1; i<=days[m-1]; i++) {
			System.out.printf("%4d", i);
			if(++w % 7 == 0) {
				System.out.println();
			}
		}
		if(w%7 != 0) {
			System.out.println();
		}
		System.out.println("------------------------------");

		sc.close();
	}
}