콜라츠 추측 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
가운데 글자 가져오기 Level 1 #substring #length(),length,size() 차이
·
프로그래밍/알고리즘(자바)
가운데 글자 가져오기 Level 1https://programmers.co.kr/learn/challenge_codes/82 length와 length(), size()들의 차이점은 아래 링크에 잘 설명 되어 있다. length와 length(), size()들의 차이점 즉 length는 배열, length()는 문자열, size는 콜렉션, 셋 객체에서 사용한다. class StringExercise{ String getMiddle(String word){ return word.substring((word.length()-1)/2,word.length()/2+1) ; //length()-1 후에 나누기 2 해야 함에 유의!! //subString이 아니라 substring이다. //substring(여기..
약수의 합 Level 1
·
프로그래밍/알고리즘(자바)
약수의 합 Level 1 class SumDivisor { public int sumDivisor(int num) { int answer = 0; for(int i=1;i