
- ๋ฌธ์ : ๋ฌธ์์ด S์ ๊ฑฐ๋ฆฌn์ ์ ๋ ฅ๋ฐ์ n๋งํผ ์ด๋์ํจ ์ํธ๋ฌธ์ ๋ง๋ค๊ธฐ package org.example; public class proPrac23 { public String solution(String s, int n) { String answer = ""; for(int i=0; i

- ๋ฌธ์ : nums์ ์๋ ์ซ์ ์ค ์๋ก ๋ค๋ฅธ 3๊ฐ๋ฅผ ๊ณจ๋ผ ๋ํ์ ๋ ์์๊ฐ ๋๋ ๊ฒฝ์ฐ์ ์ ๊ตฌํ๊ธฐ package org.example; public class proPrac22 { public static void main(String[] args) { int nums[] = {1,2,7,6,4}; int answer = 0; for (int i = 0; i < nums.length; i++) { for (int j = i + 1; j < nums.length; j++) { for (int k = j + 1; k < nums.length; k++) { // ๋ชจ๋ ๊ฒฝ์ฐ์์๋ฅผ ๊ตฌํ๊ธฐ์ํด์ ์ผ์ค for๋ฌธ์ ์ฌ์ฉ int sum = nums[i] + nums[j] + nums[k]; // num i + num..

- ๋ฌธ์ : ํญํด ์ฒดํฌ์ธ/์ฒดํฌ์์ ๋ฐฐ์ด์ ๊ณ์ฐํ์ฌ ์ด๋ฒ์ฃผ์ ์ด ๋ช์๊ฐ์ ๊ณต๋ถํ๋์ง ๊ตฌํ๋ ๋ฌธ์ ์๋ฒฝ 5์ ์ ๊ฐ์ด๊ฑฐ๋, ์ดํ ์ฒดํฌ์์์ ํ์์ ๋๋ ์ฒดํฌ์์์ ๊น๋จน์๊ฒ์ผ๋ก ๊ฐ์ฃผํ์ฌ 21์๊น์ง ํ๊ฒ์ผ๋ก ํจ package examPrac; public class exam2 { public static class Main { public int solution(int[] arr1, int[] arr2) { int answer = 0; // ๋ต์ ๋ฆฌํดํ ์ ์ํ ๋ณ์๋ฅผ ์ ์ธ (์ด ์๊ฐ์ผ ํฉ์ ๋ฐํํ ๊ฑฐ๊ธฐ ๋๋ฌธ์ ์ ์ํ์ผ๋ก ์ ์ธํจ) int result = 0; // ์ด ์๊ฐ ๊ณ์ฐ์ ์ฌ์ฉํ ๋ณ์ ์ ์ธ int timeOut = 21; // 29์(5์)๊ฐ ๋์ด๊ฐ๊ฒฝ์ฐ 21์๊น์ง ํ๊ฒ์ผ๋ก ๊ฐ์ฃผํ์ฌ ๊ณ์ฐํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ซ์ 2..

- ๋ฌธ์ : ํญํด 1์ผ์ฐจ ๋ ์ง๋ฅผ ์ ๋ ฅํ๋ฉด 98์ผ ์ดํ ํญํด๋ฅผ ์๋ฃํ๊ฒ ๋๋ ๋ ์ง๋ฅผ ๊ณ์ฐํ๋ ์๊ณ ๋ฆฌ์ฆ์ ๋ง๋ค๊ธฐ ์ค์ผ์ ๊ณ ๋ คํ์ง์๊ณ (2์์ 28์ผ ๊น์ง), 1

- ๋ฌธ์ : ๋ฐฐ์ด์์ ๊ฐ์ฅ ์์์๋ฅผ ์ฐพ์์ ๊ฐ์ฅ ์์์๋ฅผ ์ ๊ฑฐํ ๋ฐฐ์ด์ ๋ฆฌํด ๋ง์ฝ arr์ ๊ฐ์ด [10]์ด๋ฉด, -1์ ๋ฐํ class Solution { public int[] solution(int[] arr) { if(arr.length == 1){//๋ฐฐ์ด ๊ธธ์ด๊ฐ 1์ธ(=10์ด ๋ค์ด๊ฐ์๋๊ฒฝ์ฐ) int[] answer = {-1}; // -1์ ๋ฆฌํด return answer; } int[] answer = new int[arr.length-1]; // ๊ฐ์ฅ ์์์๋ฅผ ๋นผ์ผํ๋๊น ๊ฐ์ฅ ์์์๋ฅผ ๋บ ๊ธธ์ด๋ก ์์ฑํ๋ค int min = arr[0]; // ๊ธฐ์ค๊ฐ์ ์ก๋๋ค for(int i=1; i

- ๋ฌธ์ : ์์์ ์ ์ n์ ๋ํด, ์์ ์ ์ x์ ์ ๊ณฑ์ธ์ง ์๋์ง ํ๋จํ์ฌ n์ด x์ ์ ๊ณฑ์ด๋ผ๋ฉด x+1์ ๋ฆฌํดํ๊ณ , ์๋๋ผ๋ฉด -1์ ๋ฆฌํดํ๋ค. ์ ๊ณฑ๊ทผ์ด๋ผ๋๊ฑฐ๋ถํฐ ๋ชฐ๋ผ์ ์ฐพ์์ ํธ๋๋ผ ์กฐ๊ธ ์ค๋๊ฑธ๋ ธ๋น Double n_value = Math.sqrt(n); // Math.sqrt ํจ์๋ n์ ์ ๊ณฑ๊ทผ์ ๋ฐํํ๋ค. if (n_value == n_value.intValue()) { return (long) Math.pow(n_value + 1, 2); // Math.pow๋ n_value์ 1์ ๋ํ๊ฐ์ 2๋ฒ ๊ณฑํ ๋ ์ฌ์ฉํ๋ค, } else { return -1; } - ํ์ด : java์ Mathํจ์๋ฅผ ์ด์ฉํ์ฌ ์ ๊ณฑ๊ทผ, ์ ๊ณฑํ ๊ฐ์ ๊ตฌํ ์ ์๋ค.

import java.util.Arrays; import java.util.Collections; public class proPrac8 { public static void main(String[] args) { int n = 118372; long answer = 0; String sum = ""; String page = "" + n; // ์ ์ํ n๊ฐ์ ๋ฌธ์์ด๋ก ๋ณ๊ฒฝ String[] pagen = page.split(""); // ํ์๋ฆฌ์ฉ ๋ถ๋ฆฌํ๊ธฐ์ํด์ ""์ผ๋ก ๋ถ๋ฆฌํ์ฌ ๋ฐฐ์ด์ ์ ์ฅ Arrays.sort(pagen, Collections.reverseOrder()); // ์ญ์์ผ๋ก ์ ๋ ฌ for (int i=0; i < pagen.length; i++ ){ sum += pagen[i]; // sum..

- ๋ฌธ์ : ์์ฐ์n์ ๋ค์ง์ด ๊ฐ ์๋ฆฌ ์ซ์๋ฅผ ์์๋ก ๊ฐ์ง๋ ๋ฐฐ์ด ํํ๋ก ๋ฆฌํดํ๊ธฐ 54321์ด๋ฉด [1,2,3,4,5]๋ก ๋ฆฌํดํด์ผํจ public class proPrac7 { public static void main(String[] args){ long num = 123 ; // ๋ค์ง์ด์ ๋ฐฐ์ด๋ก ๋ฐ๊ฟ ๋ณ์๋ฅผ ์ ์ธํจ String nStr = ""+num; // ์ ๋ ฅ๋ฐ์ ์ ์ํ ๋ณ์๋ฅผ String์ผ๋ก ๋ฐ๊พธ๊ธฐ ์ํด์ ์ฌ์ฉ // ๋ฌธ์์ด + ์ ์ํ๋ณ์๋ฅผ ๋ํ๋ฉด ๋ฌธ์์ด๋ก ๋ณํ๊ธฐ ๋๋ฌธ! StringBuffer tp = new StringBuffer(nStr); String reverse = tp.reverse().toString(); //๋ฌธ์์ด์ ๋ค์ง๊ธฐ ์ํด์ StringBuffer ํด๋์ค๋ฅผ ์ด์ฉํด ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค ..

- ๋ฌธ์ : ์์ฐ์N์ ๊ฐ ์๋ฆฟ์์ ํฉ์ ๊ตฌํด์ ๋ฆฌํดํ๊ธฐ import java.util.stream.Stream; public class proPrac6 { public static void main(String[] args) { int num = 123; // 123์ ๊ฐ ์๋ฆฟ์๋ฅผ ๋ํ์ฌ ๊ณ์ฐํ ์์ int sum = 0; int[] numArray = Stream.of(String.valueOf(num).split("")).mapToInt(Integer::parseInt).toArray(); // ์คํธ๋ง ๋ฐฐ์ด์ int ๋ฐฐ์ด๋ก ๋ณํํ๋ค. // Stream.of()๋ ์ง์ ๋ array์์ ์์ฐจ ์คํธ๋ฆผ์ ๋ง๋๋ ๋ฐ ์ฌ์ฉํจ // ํ๊ธ์ ํ๊ธ์ ๋ถ๋ฆฌํด์ผ๋๊ธฐ ๋๋ฌธ์ split("")์ ์ฌ์ฉํด์ ๋ถ๋ฆฌํ๋ค. // ..

- ๋ฌธ์ : ๋ฌธ์์ด๋ด์ ๋จ์ด๋ฅผ ์ง์๋ฒ์งธ ์ํ๋ฒณ์ ๋๋ฌธ์๋ก, ํ์๋ฒ์งธ ์ํ๋ฒณ์ ์๋ฌธ์๋ก ๋ฐ๊พผ ๋ฌธ์์ด์ ๋ฆฌํด public class proPrac4 { public static void main(String[] args) { String a = "try hello world"; // ๋ฌธ์์ด์ a์ ์ ์ฅ String[] aChange = a.split(" "); // ์ ์ฅํ ๋ฌธ์์ด์ ๊ณต๋ฐฑ์ ๊ธฐ์ค์ผ๋ก(=๋จ์ด๋ณ๋ก ํ/์ง์ ๋ณํํด์ผํ๋๊น) ๋๋์ด ๋ฐฐ์ด์ ์ ์ฅ String answer = ""; for (int i = 0; i < aChange.length; i++) { for (int j = 0; j < aChange[i].length(); j++) { // ๋ค์ค for ๋ฌธ์ ์ด์ฉํ์ฌ ๊ฐ ๋จ์ด์ ๊ธธ์ด๋งํผ ๋ฐ๋ณตํ๊ณ ,..

- ๋ฌธ์ : ๋ง๋ผํค์ ์ฐธ์ฌํ ์ ์๋ค์ ์ด๋ฆ์ด ๋ด๊ธด ๋ฐฐ์ด๊ณผ, ์์ฃผํ ์ ์๋ค์ ์ด๋ฆ์ด ๋ด๊ธด ๋ฐฐ์ด์ ๋น๊ตํ์ฌ ์์ฃผํ์ง ๋ชปํ ์ ์์ ์ด๋ฆ์ returnํ๋ ๋ฌธ์ import java.util.Arrays; public class proPrac5 { public static void main(String[] args) { String[] participant = { "leo", "kiki", "eden"}; // ๋ง๋ผํค ์ฐธ์ฌ ์ ์์ ๋ช ๋จ์ ์ ์ฅํ๋ค. String[] completion = {"eden", "kiki"}; // ๋ง๋ผํค ์ฐธ์ฌ ์ ์ ์ค ์ฑ๊ณตํ ์ ์์ ๋ช ๋จ์ ์ ์ฅํ๋ค String answer = ""; Arrays.sort(participant); Arrays.sort(completion); // ์ฐธ์ฌ ..

- ๋ฌธ์ : n์ ํจํด๋งํผ "์๋ฐ์๋ฐ์.."๋ฅผ ์ถ๋ ฅํ๋ ๋ฌธ์ ๋ณ๊ฑฐ ์๋๋ฐ ์ด๋ป๊ฒ ํ์ด์ผํ ์ง ํ์ฐธ ๊ณ ๋ฏผํ๋น public class proPrac2 { public static void main(String[] args) { int n = 5; // n์ ๊ฐ์ ์ ์ฅํ๋ ๋ณ์ String result = ""; // ๊ฒฐ๊ณผ๊ฐ์ ์ถ๋ ฅํ String๋ณ์๋ฅผ ์ ์ธํ๋ค for (int i = 0; i < n; i++) // i๋ 0๋ถํฐ n๊น์ง ๋ฐ๋ณต result += i % 2 == 0 ? "์" : "๋ฐ"; // i๋ฅผ 2๋ก ๋๋ ๋๋จธ์ง๊ฐ 0์ด๋ฉด(์ฐธ์ด๋ฉด), "์" ๊ฑฐ์ง์ด๋ฉด "๋ฐ" System.out.println(result); } } - ํ์ด ์ด ๋ฌธ์ ๋ ๊ฐ๋จํ๋ ํ์ด๋ ํจ์คํ๋ค.

- ๋ฌธ์ : ๋ฐฐ์ด์ element ์ค divisor ๋ก ๋๋์ด ๋จ์ด์ง๋ ๊ฐ์ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌํ ๋ฐฐ์ด์ ๋ฐํ divisor๋ก ๋๋์ด ๋จ์ด์ง๋ element๊ฐ ์๋ค๋ฉด ๋ฐฐ์ด์ -1์ ๋ด์ ๋ฐํํ๋ค. import java.util.ArrayList; import java.util.Arrays; class proPrac1 { public static void main(String[] args) { int[] arr = {5, 9, 7, 10}; // arr ๋ฐฐ์ด ์์ฑ int divisor = 5; // divisor ๊ฐ ๋ด์ ๋ณ์ ์์ฑ int[] answer = {}; ArrayList list = new ArrayList(); // division ์ฐ์ฐ์ ์ํ ArrayList ์ ์ธ for (int i = 0..

- ๋ฌธ์ : 2016๋ ์ ์ค๋ ์ด๊ณ , 2016๋ 1์ 1์ผ์ ๊ธ์์ผ์ด๋ค. ์(a),์ผ(b)์ ์ ๋ ฅ๋ฐ๊ณ ํด๋น ๋ ์ง๊ฐ ๋ฌด์จ ์์ผ์ธ์ง ๋ฆฌํดํ๋ ํจ์๋ฅผ ์์ฑํ๋ผ -ํ์ด : public class HomeworkPrac4 { public static void main(String[] args){ int a = 5; // ์ ์ ๋ ฅ ๋ฐ์ ๋ณ์ ์ ์ธ int b = 24; // ์ผ ์ ๋ ฅ ๋ฐ์ ๋ณ์ ์ ์ธ // ๋ด๊ฐ ์๊ฐํ ๋ฌธ์ ํ์ด ๋ฐฉ๋ฒ : a์ b์ผ๊น์ง์ ๋ชจ๋ ์ผ์๋ฅผ ๋ํ ํ, 7์ผ๋ก ๋๋ ์ ๋งค์นญ๋๋ ์์ผ์ ์ถ๋ ฅํ๊ณ ์ํจ int[] monthsDay = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 2016๋ ์ ์ค๋ ์ด๋ฏ๋ก 2์์ด 29์ผ๊น์ง ์๋ค. ๋งค์ ๋ช์ผ๊น์ง ์๋์ง mont..