전체 글70 [프로그래머스] K번째 수 프로그래머스 1단계 K번째 수 https://programmers.co.kr/learn/challenges 문제 설명 풀이 import java.util.Arrays; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; int[] number = new int[array.length]; for(int i=0; i 2022. 4. 24. [프로그래머스] 콜라츠 추측 프로그래머스 1단계 콜라츠 추측 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public int solution(double num) { int answer = 0; if(num == 1) { return 0; } while(num != 1) { if(answer == 500) { return -1; } if(num % 2 == 0) { num /= 2; answer++; } else { num = num * 3 + 1; answer++; } System.out.print(num+" "); } return answer; } } 2022. 4. 23. [알고리즘] 선택정렬 알고리즘 선택정렬 JAVA 코드 data[10] : 정렬할 숫자가 저장 될 배열 count : 입력 받은 숫자의 개수가 저장 될 변수 i : 정렬 회전 수, 비교 기준 값이 있는 위치를 지정해 주는 변수 j : 비교 대상이 있는 위치를 지정해주는 변수 k : 자료를 교환할 때 사용할 임시 변수 num : 출력할 때 배열의 위치를 지정해 주는 변수 for문 public class sort_1 { public static void main(String[] args) { int count,i,j,k,num; int data[] = new int[10]; Scanner scan = new Scanner(System.in); for(count=0; count 2022. 4. 23. [프로그래머스] 짝수와 홀수 프로그래머스 1단계 짝수와 홀수 https://programmers.co.kr/learn/challenges 문제 설명 제한 조건 - num은 int 범위의 정수입니다. - 0은 짝수입니다. 풀이 class Solution { public String solution(int num) { String answer; if(num%2==0) answer = "Even"; else answer = "Odd"; return answer; } } 2022. 4. 23. [프로그래머스] x만큼 간격이 있는 n개의 숫자 프로그래머스 1단계 x만큼 간격이 있는 n개의 숫자 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public long[] solution(long x, int n) { long[] answer; answer = new long[n]; for(int i=0; i 2022. 4. 23. [프로그래머스] 평균 구하기 프로그래머스 1단계 평균 구하기 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public double solution(int[] arr) { double answer = 0; for(int i = 0; i 2022. 4. 23. [프로그래머스] 자릿수 더하기 프로그래머스 1단계 자릿수 더하기 https://programmers.co.kr/learn/challenges 문제 설명 풀이 public class Solution { public int solution(int n) { int answer = 0; while(n>0) { answer += n % 10; n /= 10; } return answer; } } 2022. 4. 23. [프로그래머스] 수박수박수박수박수박수? 프로그래머스 1단계 수박수박수박수박수박수? https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public String solution(int n) { String answer = ""; for(int i=1; i 2022. 4. 23. [프로그래머스] 서울에서 김서방 찾기 프로그래머스 1단계 서울에서 김서방 찾기 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public String solution(String[] seoul) { int i; String key = "Kim"; for(i=0; i 2022. 4. 23. 이전 1 ··· 4 5 6 7 8 다음