๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

๊ฐœ๋ฐœ93

[JAVA] ์ ‘๊ทผ์ œํ•œ์ž๊ฐ€ private์ธ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ• ์ฃผ๋ฌธ๋ฒˆํ˜ธ๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๊ฐ–๋Š” Order ํด๋ž˜์Šค์˜ canCancel ๋ฉ”์†Œ๋“œ๊ฐ€ private๋กœ ์„ ์–ธ๋˜์–ด ์žˆ์„ ๋•Œ ์ด ๋ฉ”์†Œ๋“œ๋ฅผ ์™ธ๋ถ€์—์„œ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. Order order = new Order(); Method method = order.getClass().getDeclaredMethod("canCancel", Order.class); method.setAccessible(true); boolean result = (boolean)method.invoke(order, "์ฃผ๋ฌธ๋ฒˆํ˜ธ"); 2022. 10. 13.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] ์ฒด์œก๋ณต ๐Ÿ‘‡ ๋ฌธ์ œ URL ๐Ÿ‘‡ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํƒ์š•๋ฒ• ๋ฌธ์ œ! ํƒ์š•๋ฒ•์ด๋ž€ ๋งค ์„ ํƒ์—์„œ ์ตœ์ ์˜ ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค์–ด๋‚ด๋Š” ๊ฒƒ. import java.util.Arrays; class Solution { public int solution(int n, int[] lost, int[] reserve) { int answer = n; int[] student = new int[n]; //์ผ๋‹จ ๋ชจ๋‘ ์ฒด์œก๋ณต์„ ๊ฐ€์ ธ์˜จ ๊ฒƒ์œผ๋กœ ์„ธํŒ… (1,1,1,1,1) Arrays.fill(student, 1); Arrays.sort(lost); Arrays.sort(rese.. 2022. 7. 25.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ ๐Ÿ‘‡ ๋ฌธ์ œ URL ๐Ÿ‘‡ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr 2,5,8,0์ผ ๊ฒฝ์šฐ ์˜ค๋ฅธ์†, ์™ผ์†์ด ์œ„์น˜ํ•œ ํ‚คํŒจ๋“œ์—์„œ์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•ด์•ผ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ขŒํ‘œ๋ฅผ ์ด์šฉํ•˜์—ฌ ํ’€์—ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  Stream API์— ์žˆ๋Š” anyMatch๋ฅผ ์ด์šฉํ•˜์—ฌ ์ตœ์†Œํ•œ ํ•œ ๊ฐœ์˜ ์š”์†Œ๊ฐ€ ์ฃผ์–ด์ง„ ์กฐ๊ฑด์— ๋งŒ์กฑํ•˜๋Š”์ง€๋ฅผ ์ฒดํฌํ•˜์˜€๋‹ค. import java.util.Arrays; class Solution { public String solution(int[] numbers, String hand) { String answer = ""; int[] leftHand = {1,4,7}; int[].. 2022. 7. 25.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] ์ˆซ์ž ๋ฌธ์ž์—ด๊ณผ ์˜๋‹จ์–ด ๐Ÿ‘‡ ๋ฌธ์ œ URL ๐Ÿ‘‡ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์†Œ์Šค ์ฝ”๋“œ String[] engNum = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; //i๋Š” 0~9 for(int i=0; i 2022. 7. 24.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] ์‹ ๊ทœ ์•„์ด๋”” ์ถ”์ฒœ ๐Ÿ‘‡ ๋ฌธ์ œ URL ๐Ÿ‘‡ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr class Solution { public String solution(String new_id) { String answer = ""; //1๋‹จ๊ณ„ new_id = new_id.toLowerCase(); System.out.println("1๋‹จ๊ณ„ :"+new_id); //2๋‹จ๊ณ„ StringBuffer sb = new StringBuffer(); for(int i=0; i= 16){ new_id = new_id.substring(0, 15); new_id = new_id.replaceAll(.. 2022. 7. 24.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„ ๐Ÿ‘‡ ๋ฌธ์ œ URL ๐Ÿ‘‡ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr class Solution { public int[] solution(int[] lottos, int[] win_nums) { int[] answer = new int[2]; int cnt = 0; int zeroCnt = 0; for(int num : lottos){ if(num ==0){ zeroCnt ++; } for(int win_num : win_nums){ if(num == win_num){ cnt++; } } } int minCnt = cnt; int maxCnt = cnt+z.. 2022. 7. 24.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ ๐Ÿ‘‡ ๋ฌธ์ œ URL ๐Ÿ‘‡ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr import java.util.HashMap; import java.util.HashSet; import java.util.Map; public static int[] solution(String[] id_list, String[] report, int k) { int[] answer = new int[id_list.length]; // HashMap : Key-value, hashSet: set ์ค‘ ์„ฑ๋Šฅ์ด ๊ฐ€์žฅ ์ข‹์Œ // key : ์‹ ๊ณ ๋œ ID, value : ์‹ ๊ณ ํ•œ ID set Map .. 2022. 7. 24.
[Spring] ๋นˆ(bean)์„ ๋“ฑ๋กํ•˜๋Š” ๋ฐฉ๋ฒ• 1. ์ปดํฌ๋„ŒํŠธ ์Šค์บ”๊ณผ ์ž๋™ ์˜์กด๊ด€๊ณ„ ์„ค์ • ์ปดํฌ๋„ŒํŠธ ์Šค์บ”์˜ ์›๋ฆฌ @Component ์–ด๋…ธํ…Œ์ด์…˜์ด ์„ ์–ธ๋˜์–ด ์žˆ์œผ๋ฉด ์Šคํ”„๋ง ๋นˆ์œผ๋กœ ์ž๋™ ๋“ฑ๋ก @Controller ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์Šคํ”„๋ง ๋นˆ์œผ๋กœ ์ž๋™ ๋“ฑ๋ก๋œ ์ด์œ ๋„ ์ปดํฌ๋„ŒํŠธ ์Šค์บ” ๋•Œ๋ฌธ! (@Controller ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ดํŽด๋ณด๋ฉด @Component๊ฐ€ ์„ ์–ธ๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Œ) @Service, @Repository๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ @Component๊ฐ€ ์„ ์–ธ๋˜์–ด ์žˆ์–ด ์Šคํ”„๋ง ๋นˆ์œผ๋กœ ์ž๋™ ๋“ฑ๋ก ๋œ๋‹ค. ์˜ˆ์‹œ OrderController.java @Controller public class OrderController { private final OrderService orderService; @Autowired public OrderController(OrderServic.. 2022. 7. 1.
728x90
๋ฐ˜์‘ํ˜•