CodingTest 124

[프로그래머스 / Java] Lv.1 자릿수 더하기

Question https://school.programmers.co.kr/learn/courses/30/lessons/12931 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCodeimport java.util.*;public class Solution { public int solution(int n) { int answer = 0; while(n > 0) { answer += n % 10; n = n / 10; } return answer; }}n % 10 : n의 마지막 자릿수를 구..

[프로그래머스 / Java] Lv.1 약수의 합

Question https://school.programmers.co.kr/learn/courses/30/lessons/12928 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡내 풀이class Solution { public int solution(int n) { int answer = 0; for(int i = 1; i 💡참고하면 좋은 풀이class SumDivisor { public int sumDivisor(int num) { int answer = 0; for(int i = 1 ; i

[프로그래머스 / Java] Lv.0 문자 반복 출력하기

Question https://school.programmers.co.kr/learn/courses/30/lessons/120825 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCodeclass Solution { public String solution(String my_string, int n) { String answer = ""; String[] str = my_string.split(""); for(int i = 0; i split(String regex) regex : 문자열을 분할할 기준이 되는 정규 표현식입니다.rep..

[프로그래머스 / Java] Lv.0 아이스 아메리카노

Question https://school.programmers.co.kr/learn/courses/30/lessons/120819 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡내 풀이class Solution { public int[] solution(int money) { int[] answer = new int[2]; answer[0] = money / 5500; answer[1] = money % 5500; return answer; }} 💡참고하면 좋은 풀이class Solution { ..

[프로그래머스 / Java] Lv.0 특정 문자 제거하기

Question https://school.programmers.co.kr/learn/courses/30/lessons/120826 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCodeclass Solution { public String solution(String my_string, String letter) { String answer = ""; answer = my_string.replace(letter,""); return answer; }} 💡문자열 치환 함수replace(CharSequence old, CharS..

[프로그래머스 / Java] Lv.0 짝수 홀수 개수

Question https://school.programmers.co.kr/learn/courses/30/lessons/120824 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡 방법 1class Solution { public int[] solution(int[] num_list) { int[] result; int even = 0; int odd = 0; for(int i = 0; i * 배열 선언 및 초기화 1. 배열 선언 후 크기 지정int[] arr = new int[5]; 2. 선언과 초기화를 동..

[프로그래머스 / Java] Lv.0 제곱수 판별하기

Question https://school.programmers.co.kr/learn/courses/30/lessons/120833?language=java 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode방법 1.class Solution { public int[] solution(int[] numbers, int num1, int num2) { int [] answer = new int[num2 - num1 + 1]; int index = 0; for (int i = num1; i * 배열 선언 및 초기화 1. 배열 선언 ..

[프로그래머스 / Java] Lv.0 점의 위치 구하기

Question https://school.programmers.co.kr/learn/courses/30/lessons/120841 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode방법 1. elseif (dot[0] > 0) { if (dot[1] > 0) answer = 1; else answer = 4;} else { if (dot[1] > 0) answer = 2; else answer = 3;}1) 장점else는 if 조건이 false일 때만 실행되므로 불필요한 조건 검사를 피합니다.2) 단점로직이 복잡해지면, else만 사용했을 때 어떤 조건을 처리하고 있는지 명확하..