프로그래머스 짝수는 싫어요(자바) class Solution { public int[] solution(int n) { int[] answer = new int[(n+1)/2]; //배열 크기 설정 int a = 0; //배열 인덱스를 위한 변수 생성 for(int i=0; i JavaAlgorithm 2023.10.30
프로그래머스 모음 제거(자바) replaceAll을 이용해 a,e,i,o,u를 ""로 바꿔주었습니다. class Solution { public String solution(String my_string) { String answer = ""; answer = my_string.replaceAll("[a,i,e,o,u]", ""); return answer; } } JavaAlgorithm 2023.10.30
프로그래머스 제곱수 판별(자바) public class SquareNumber { public static void main(String[] args) { int answer = 0; int n = 144; for(int i=1; i JavaAlgorithm 2023.10.25
프로그래머스 중앙값 구하기(자바) 방법1. public class CenterValue { public static void main(String[] args) { int[] array = {9,-1,0}; int answer = 0; int a = array.length/2;//가운데 순번 //배열값 오름차순 정렬 for(int i=0; i JavaAlgorithm 2023.10.25
프로그래머스 문자 반복 출력하기(자바) 문자열 my_string과 정수n이 매개변주로 주어질 때, my_string에 들어있는 각 문자를 n만큼 반복하시오. 방법1. public String solution(String my_string, int n) { String[] list = my_string.split("");//문자열 배열로 변환 StringBuilder answerA = new StringBuilder();//append사용을 위한 StringBuilder 생성 for(int i=0; i JavaAlgorithm 2023.08.14
프로그래머스 순서쌍의 개수(자바) 자연수n이 매개변수로 주어질 때 두 숫자의 곱이 n인 자연수 순서쌍의 개수를 return하도록 완성해주세요. n이 20이면 곱이 20인 순서쌍은 (1,20) (2,10) (4,5) (5,4) (10,2) (20,1)이므로 6을 return합니다. 방법1. public int solution(int n) { int answer = 0; for(int i = 1; i n % i == 0).count(); } } JavaAlgorithm 2023.08.11
프로그래머스 문자열 안에 문자열(자바) 문자열 str1, str2가 매개변수로 주어집니다. str1안에 str2가 있다면 1을 없다면 2를 return하도록 함수를 완성해주세요 방법1. public int solution(String str1, String str2) { int answer = 0; if(str1.contains(str2)) { answer = 1; }else { answer = 2; } return answer; } 방법2. public int solution(String str1, String str2) { return (str1.contains(str2)? 1: 2); } JavaAlgorithm 2023.08.10
프로그래머스 특정 문자 제거하기(자바) 문자열 my_string와 문자 letter이 매개변수로 주어집니다. my_string에서 letter를 제거한 문자열을 return하도록 완성해주세요 class Solution { public String[] solution(String my_string, String letter) { String[] answer = my_string.split(letter); return answer; } } JavaAlgorithm 2023.08.10
배열의 각 원소의 길이 출력(자바) 배열에서 각 원소의 문자열 길이를 출력해 보겠습니다. public class LengthOfArray { public static void main(String[] args) { String[] strlist = {"we", "are", "the", "world"}; int[] answer = new int[strlist.length]; for(int i = 0; i < strlist.length; i++) { answer[i] = strlist[i].length(); } //answer의 값들을 꺼내기 위한 향상된 for문 for(int result : answer ) { System.out.print(result + " "); } } } JavaAlgorithm 2023.08.08
프로그래머스 배열 유사도(자바) 두 배열이 얼마나 유사한지 확인하기 배열 s1,s2의 원소를 비교해 같은 원소의 개수를 구하시오. 방법1. public int solution(String[] s1, String[] s2) { int answer = 0; for(int i=0; i JavaAlgorithm 2023.08.07