본문 바로가기

전체 글

정수 내림차순으로 배치하기 Level 2 #split #Arrays.sort #Collections.reverse #Arrays.asList #String.join 정수 내림차순으로 배치하기 Level 2 #split String 타입 변수 -> String 타입 배열로 만들어 준다. #Arrays.sort 오름차순! #Collections.reverse 역 ( 내림차순! ) #Arrays.asList 배열을 list형으로 변환. Collections과 Arrays의 중간다리역할이다. #String.join split의 반대. 배열을 하나의 변수로 묶어준다. import java.util.Arrays; import java.util.Collections; public class ReverseInt { public int reverseInt(int n){ String[] arr = String.valueOf(n).split(""); // int 형을 String 타입.. 더보기
2016년 Level 2 #달력(요일) 알고리즘 2016년 Level 2 class TryHelloWorld { public String getDayName(int a, int b) { String answer = ""; String[] dayName = {"SUN","MON","TUE","WED","THU","FRI","SAT"}; int[] month = {31,29,31,30,31,30,31,31,30,31,30,31}; int day = 5; //1월 1일 : 금요일 for(int i = 1 ; i 더보기
콜라츠 추측 Level 2 #삼항연산자 콜라츠 추측 Level 2https://programmers.co.kr/learn/challenge_codes/13class Collatz { public int collatz(int num) { int answer = 0; while(answer 더보기
최솟값 만들기 Level 2 #Arrays.sort 최솟값 만들기 Level 2 import java.util.Arrays; class TryHelloWorld { public int getMinSum(int []A, int []B) { int answer = 0; Arrays.sort(A); // Arrays.sort(B); for(int i=0; i 더보기
소수 찾기 Level 2 #Math.sqrt #소수 소수 찾기 Level 2 class NumOfPrime { int numberOfPrime(int n) { int result = 0; for (int i = 2; i 더보기
삼각형출력하기 Level 1 삼각형출력하기 Level 1https://programmers.co.kr/learn/challenge_codes/103/어떻게 하면 for문 하나로 처리할 수 있을까 고민해서 작성했더니 추천수가 가장 높은 코딩방법과 거의 유사(좀 더 깔끔)하게 나와 흡족하다.public class PrintTriangle { public String printTriangle(int num){ String star = ""; String print = ""; for(int i = 0 ; i 더보기
수박수박수박수박수박수? Level 1 #join #replace #StringBuffer #append #String '+=' 연산 수박수박수박수박수박수? Level 1 이 문제는 푸는 방식이 정말 다양했다.일단 join을 이용해 풀었는데 String API를 보니 concat 메소드로도 가능할 것 같다.public class WaterMelon { public String watermelon(int n){ String wm =""; for(int i = 0; i 더보기
최대공약수와 최소공배수 Level 1 #유클리드 호제법 최대공약수와 최소공배수 Level 1 # 유클리드 호제법https://ko.wikipedia.org/wiki/%EC%9C%A0%ED%81%B4%EB%A6%AC%EB%93%9C_%ED%98%B8%EC%A0%9C%EB%B2%95 class TryHelloWorld { public int[] gcdlcm(int a, int b) { int a_ , b_ , temp; //LCM = A*B / GCD //GCD = A'* B' //A = A'* GCD //B = B'* GCD if(a 더보기