➜ 코딩 테스트/프로그래머스

프로그래머스 - 9로 나눈 나머지

class Solution { public int solution(String number) { int answer = 0; for(int i = 0; i < number.length(); i++){ answer += Integer.parseInt(String.valueOf(number.charAt(i))); } return answer % 9; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - 주사위 게임 3

import java.util.Arrays; class Solution { public int solution(int a, int b, int c, int d) { int[] dice = {a, b, c, d}; Arrays.sort(dice); // 모두 같은 숫자인 경우 if (dice[0] == dice[1] && dice[1] == dice[2] && dice[2] == dice[3]) { return 1111 * dice[0]; } // 세 개가 같은 숫자인 경우 else if ((dice[0] == dice[1] && dice[1] == dice[2]) || (dice[1] == dice[2] && dice[2] == dice[3])) { int sameValue = dice[1]; int d..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 간단한 논리 연산

class Solution { public boolean solution(boolean x1, boolean x2, boolean x3, boolean x4) { return (x1 || x2) && (x3 || x4); } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - 특정한 문자를 대문자로 바꾸기

class Solution { public String solution(String my_string, String alp) { String answer = ""; answer = my_string.replaceAll(alp , alp.toUpperCase()); return answer; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - rny_string

class Solution { public String solution(String rny_string) { String answer = ""; for(int i = 0; i < rny_string.length(); i++){ if(rny_string.charAt(i) == 'm'){ answer += "rn"; }else{ answer += rny_string.charAt(i); } } System.out.println(answer); return answer; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - n 번째 원소까지

class Solution { public int[] solution(int[] num_list, int n) { int[] answer = new int[n]; for(int i = 0; i < n; i++){ answer[i] = num_list[i]; } return answer; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - 글자 이어 붙여 문자열 만들기

class Solution { public String solution(String my_string, int[] index_list) { String answer = ""; String[] str = new String[my_string.length()]; for(int i = 0; i< str.length; i++){ str[i] = String.valueOf(my_string.charAt(i)); } for(int i = 0; i < index_list.length; i++){ answer += str[index_list[i]]; } System.out.println(answer); return answer; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - 정수 찾기

class Solution { public int solution(int[] num_list, int n) { int answer = 0; for(int i = 0; i < num_list.length; i++){ if(num_list[i] == n){ answer = 1; } } return answer; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - 주사위 게임 1

class Solution { public int solution(int a, int b) { int answer = 0; if(a % 2 == 1 && b % 2 == 1){ answer = a*a + b*b; }else if( (a % 2 == 1 && b % 2 == 0) || (a % 2 == 0 && b % 2 == 1)){ answer = 2*(a+b); }else{ answer = Math.abs(a - b); } return answer; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - 공백으로 구분하기 2

import java.util.*; class Solution { public String[] solution(String my_string) { my_string = my_string.trim(); String[] answer = my_string.split("\\s+"); System.out.println(Arrays.toString(answer)); return answer; } }

강맹석
'➜ 코딩 테스트/프로그래머스' 카테고리의 글 목록 (29 Page)