Banner

My Tech Blog (์ถœ๋ ฅ)

์ถœ๋ ฅํ•  ๋•Œ ์ œ๋ชฉ์„ ์œ„์— ๊ณ ์ •ํ•ด์„œ ๋งค ํŽ˜์ด์ง€๋งˆ๋‹ค ๋ฐ˜๋ณต ์ถœ๋ ฅ๋˜๊ฒŒ ํ•˜๋Š” ๋ฒ•์ƒ๋‹จ ๋ฆฌ๋ณธ๋ฉ”๋‰ดํŽ˜์ด์ง€ ๋ ˆ์ด์•„์›ƒ ํƒญ ํŽ˜์ด์ง€ ์„ค์ • ๊ทธ๋ฃน์—์„œ ์ธ์‡„ ์ œ๋ชฉ ๋ฒ„ํŠผ ํด๋ฆญ ๋‚˜ํƒ€๋‚˜๋Š” ์ฐฝ์—์„œ ์‹œํŠธ ํƒญ ์„ ํƒ ๋ฐ˜๋ณตํ•  ํ–‰์—์„œ ๊ณ ์ •ํ•˜๊ณ  ์‹ถ์€ ํ–‰์„ ์„ ํƒ ์˜ˆ: $1:$1 → ์ฒซ ๋ฒˆ์งธ ํ–‰์„ ๋ฐ˜๋ณต ์˜ˆ: $2:$3 → ๋‘ ๋ฒˆ์งธ์™€ ์„ธ ๋ฒˆ์งธ ํ–‰์„ ๋ฐ˜๋ณต ํŽ˜์ด์ง€ ๋ ˆ์ด์•„์›ƒ์—์„œ "๋ฐ˜๋ณตํ•  ํ–‰"์„ ์ง€์ •ํ•  ๋•Œ๋Š” ์ ˆ๋Œ€์ฐธ์กฐ($) ํ˜•์‹์„ ์‚ฌ์šฉํ•ด์•ผ ํ•จ. ์ ˆ๋Œ€์ฐธ์กฐ ์—†์ด 1:1์ฒ˜๋Ÿผ ์ž…๋ ฅํ•˜๋ฉด, ์—‘์…€์ด ์ด๋ฅผ ์ œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•˜๋ฏ€๋กœ ๊ผญ $๋ฅผ ๋ถ™์—ฌ ์‚ฌ์šฉํ•˜๊ธฐ๐Ÿ˜Š ์ฐธ๊ณ ๋กœ ์—ด์ด ์•ˆ ๋งž์„ ๋•Œ๋Š” [์ธ์‡„] > [์„ค์ •] > [ํ•œ ํŽ˜์ด์ง€์— ๋ชจ๋“  ์—ด ๋งž์ถ”๊ธฐ] ์„ ํƒํ•˜์ž ๊ทธ๋Ÿผ ์ถœ๋ ฅํ• ๋•Œ ํŽ˜์ด์ง€๋งˆ๋‹ค ์ œ๋ชฉ์ด ๋ถ™์–ด์„œ ๋‚˜์˜จ๋‹ค
1. ์ œ๋„ค๋ฆญ์Šค(Generics) ์ œ๋„ค๋ฆญ์Šค๋ž€?์ œ๋„ค๋ฆญ์Šค(generics)๋Š” ์ž๋ฐ” J2SE 5.0 ๋ฒ„์ „ ์ดํ›„์— ๋„์ž…๋œ ๊ฐœ๋…์œผ๋กœ, ์ž๋ฃŒํ˜•์„ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด ์ฃผ๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. ์ œ๋„ค๋ฆญ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ž๋ฃŒํ˜•์„ ๊ฐ•์ œ๋กœ ๋ฐ”๊ฟ€ ๋•Œ ์ƒ๊ธธ ์ˆ˜ ์žˆ๋Š” ์บ์ŠคํŒ…(Casting) ์˜ค๋ฅ˜๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค. ArrayList๋Š” ์ž๋ฐ”์˜ **์ œ๋„ค๋ฆญ์Šค(Generics)**๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋Œ€ํ‘œ์ ์ธ ์ปฌ๋ ‰์…˜ ํด๋ž˜์Šค์ด๋‹ค. ์ œ๋„ค๋ฆญ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ArrayList์— ์ €์žฅํ•  ์š”์†Œ์˜ ํƒ€์ž…์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๊ณ , ๋•๋ถ„์— ํ˜• ๋ณ€ํ™˜ ์—†์ด ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•œ๋‹ค. (ํƒ€์ž… ์•ˆ์ •์„ฑ ๋ณด์žฅ) ArrayList๋Š” ArrayList ํ˜•ํƒœ๋กœ ์ •์˜ํ•˜๋Š”๋ฐ, ์—ฌ๊ธฐ์„œ E๋Š” ์ €์žฅํ•  ์š”์†Œ์˜ ํƒ€์ž…์„ ๋‚˜ํƒ€๋‚ด๋Š” ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜์ด๋‹ค. ArrayList,ArrayList์ฒ˜๋Ÿผ ์ œ๋„ค๋ฆญ์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ •..
โœ… ๋ฌธ์ œ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณ„์˜ ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ๋ฐฐ์—ด ์ธ๋ฑ์Šค์˜ ์ˆ˜ ๋งŒํผ ๋ณ„ ์ฐ๊ธฐ โœ… ์ฝ”๋“œimport java.util.Scanner;public class bonus04 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] cc = new int[5]; // ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ์ˆซ์ž ์ž…๋ ฅ ๋ฐ›๊ธฐ for (int i = 0; i  ์ผ๋ฐ˜ ๋ณ„์ฐ๊ธฐ๋ณด๋‹ค ์˜คํžˆ๋ ค ์‰ฝ๋‹ค. ์ž…๋ ฅ๋ฐ›์€ ์ˆซ์ž๋ฅผ ๋ฐฐ์—ด์— ์ €์žฅํ•˜๊ณ  9 : ********* ์ด ๋ถ€๋ถ„์„ ๋‘ ๊ตฌ๊ฐ„์œผ๋กœ ๋‚˜๋ˆ„์–ด์„œ '์ˆซ์ž :' ๊ณผ '*********' ๋ฅผ ๋”ฐ๋กœ ์ถœ๋ ฅํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์งœ ์ฃผ์—ˆ๋‹ค.์ˆซ์ž๋Š” ๋ฐฐ์—ด์˜[i] ๋ฒˆ์งธ ์ธ๋ฑ์Šค์— ๋‹ด๊ฒจ ์žˆ์œผ๋ฏ€๋กœ cc..
โœ… ๋ฌธ์ œ๊ณ„์‚ฐ๊ธฐ ๋งŒ๋“ค๊ธฐ โœ… ์ถ”๋ก  ๊ณผ์ • ๋‘ ๊ฐœ์˜ ์ •์ˆ˜์™€ ์—ฐ์‚ฐ์ž๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„์„œ ํ•ด๋‹น ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฐ„๋‹จํ•œ ๊ณ„์‚ฐ๊ธฐ ๊ตฌํ˜„ ์ฝ”๋“œ์ด๋‹ค. ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์ด 3๊ฐœ์ด๊ณ , int ํ˜•์œผ๋กœ ๊ฒฐ๊ณผ๋ฅผ return ํ•ด ์ฃผ๋ฉด ๋˜๋Š” ์‰ฌ์šด ๋ฌธ์ œ์ด๋‹ค. ๋ฉ”์„œ๋“œ๋Š” Main ์˜์—ญ ๋ฐ–์—์„œ ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ฒฐ๊ณผ ๊ฐ’๋งŒ Main ์˜์—ญ ์•ˆ์—์„œ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค. โœ… ์ฝ”๋“œpublic class bonus03 { public static void main(String[] args) { System.out.println(cal(4, 7, '*')); } public static int cal(int num1, int num2, char op) { if (op == '+') { return n..
โœ…๋ฌธ์ œA, B ์ˆซ์ž๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.A-B๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.A์™€ B๊ฐ€ ๋ชจ๋‘ 0์„ ์ž…๋ ฅ ๋ฐ›์œผ๋ฉด ํ”„๋กœ๊ทธ๋žจ์ด ์ข…๋ฃŒ๋œ๋‹ค. โœ…์ฝ”๋“œimport java.util.Scanner;public class bonus01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { System.out.print("A ์ž…๋ ฅ >> "); int num1 = sc.nextInt(); System.out.print("B ์ž…๋ ฅ >> "); int num2 = sc.nextInt(); System.out.println("๊ฒฐ๊ณผ >> " + (num1 - num2)); if (num1 == 0 && num2 == ..
โœ… ๋ฌธ์ œ ๊ฐœ ์ถœ๋ ฅํ•˜๊ธฐโ€‹ ์ด์Šค์ผ€์ดํ”„ ์ฝ”๋“œ(Escape Sequance)๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•œ ๋ฌธ์ œ โ€‹๐Ÿ“ฅ ์ž…๋ ฅ ์—†์Œ โ€‹๐Ÿ“ฅ ์ถœ๋ ฅ ๊ฐœ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค โ€‹ ๐Ÿ’ก ํ’€์ด ์ด ๋ฌธ์ œ๋Š” ๊ณ ์–‘์ด ๋ฌธ์ œ๋ž‘ ๋งค์šฐ ์œ ์‚ฌํ•˜๋‹ค. ์ด์Šค์ผ€์ดํ”„ ์ฝ”๋“œ ์ •๋ฆฌ โ–ผ
โœ… ๋ฌธ์ œ๋ฌธ์ž์—ด ํ˜•ํƒœ์˜ 2์ง„์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ 10์ง„์ˆ˜๋กœ ๋ฐ”๊พธ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int base = 1; int result = 0; for (int i = str.length()-1 ; i >= 0; i--) { if(str.charAt(i) == '1'){ result += base; } ..
โœ… ๋ฌธ์ œ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋Œ€์‹œ('_') ๋ฌธ์ž๋กœ ๊ตฌ์„ฑ๋œ ํ˜•ํƒœ์˜ ์ˆซ์ž๋ฅผ ์ฃผ์–ด์ง„ ์ˆซ์ž์™€ ๊ฐ™์ด ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋Œ€์‹œ์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ.โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] c = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; System.out.print("์ฒซ์ž๋ฆฌ 0์„ ์ œ์™ธํ•œ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” >> "); String nums = sc.nextLine(); int result = 0; for (int i = 0; i > " + result); sc.close()..
์ธ์ ˆ๋ฏธ์˜€๋˜๊ฒƒ
'์ถœ๋ ฅ' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก
์ƒ๋‹จ์œผ๋กœ