본문 바로가기

전체 글

(283)
static에 관한 정리 참고 vaert.tistory.com/101 [Java] Static 키워드 바로 알고 사용하자 자바를 한번쯤 공부해본사람이라면 static키워드를 모르지는 않을 것입니다. 하지만, 바르게 알고 있는 사람들은 그리 많지 않습니다. 자바경력자를 면접볼 때 static키워드에 대해서 질문하곤 합 vaert.tistory.com codechacha.com/ko/java-static-keyword/ Java - Static 키워드 이해하기 Java의 static keyword는 field, method, class에 적용할 수 있습니다. static 키워드의 공통점은 객체와의 분리입니다. 객체를 생성하지 않고 접근할 수 있습니다. 또한, 어떤 클래스 아래에 static 변수, 메소 codechacha.com S..
최솟값 만들기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import java.util.*; class Solution{ public int solution(int []A, int []B) { int answer = 0; Integer[] bArray = new Integer[B.length]; for(int i = 0 ; i
배열 가변 매개변수 ... 의 형태
이름에 el이 들어가는 동물 찾기 mysql로 할 때 SELECT animal_id, name FROM animal_ins WHERE animal_type="dog" AND name LIKE "%EL%" ORDER BY name oracle 로 할 때 SELECT animal_id, name FROM animal_ins WHERE animal_type='Dog' AND UPPER(name) LIKE '%EL%' ORDER BY name upper를 안쓰면 안된다. 대소문자를 구분하기 때문이다. 그래서 animal_type 도 dog 라고 하면 안된다. 또 주의할 점이 문자열이라고 해도 오라클에서는 "" 을 취급하지 않는다. mysql과 호환이 안될 수도 있다.
이상한 문자 만들기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 class Solution { public String solution(String s) { String answer = ""; String[] str = s.split(""); String space =" "; int cnt = 0; for (int i = 0; i
콜라츠 추측 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class Solution { public int solution(int num) { int answer = 0; long number = num; while(number !=1){ if(number%2 ==0){ number /= 2; }else{ number = number *3 +1; } answer++; if(answer == 500){ answer = -1; break; } } return (int)answer; } } Colored by Color Scripter cs 로직 자체는 매우 쉽다. 반복문이든 조건문이든 어떻게 구현해도 나온다. 문제는 number를 int형으로 하면 중간에 오버플로우가 나버린다는 ..
제일 작은 수 원래 짰던 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 import java.util.*; class Solution { public static int[] minIndex(List list){ int min = list.get(0); int index = 0; for(int i : list){ if(min>i){ min = i; } } index= list.indexOf(min); list.remove(index); if(list.size() == 0){ int[] arr ={-1}; return arr; }else{ int[] arr = new int[list.size(..
문자열 내 마음대로 정렬하기 comparator 를 이용한 풀이 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.*; class Solution { public String[] solution(String[] strings, int n) { String[] answer = {}; Arrays.sort(strings,new Comparator(){ public int compare(String s1,String s2){ char c1 = s1.charAt(n); char c2 = s2.charAt(n); if(c1==c2){ return s1.compareTo(s2); }else return c1-c2; } }); return strings; } } Colored by Colo..