/* 수박수박수박수박수박수?
* 길이가 n이고, "수박수박수박수...."와 같은 패턴을 유지하는
* 문자열을 리턴하는 함수, solution을 완성하세요.
* 예를들어 n이 4이면 "수박수박"을 리턴하고 3이라면 "수박수"를 리턴하면 됩니다.
*
* n return
* 3 "수박수"
* 4 "수박수박"
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public class programmer_1_28 { static int a1 = 3; static int a2 = 4; public String solution(int n) { String answer = ""; for(int i = 1; i <= n; i++){ if(i % 2 == 0) answer += "박"; else answer += "수"; } return answer; } public static void main(String args[]){ programmer_1_28 t = new programmer_1_28(); System.out.println("---------------------------------------"); System.out.println("result = " + t.solution(a1)); System.out.println("---------------------------------------"); System.out.println("result2 = " + t.solution(a2)); System.out.println("---------------------------------------"); } } | cs |
'프로그래머스 > lv1' 카테고리의 다른 글
문자열 내림차순으로 배치하기 (0) | 2022.12.19 |
---|---|
내적 (0) | 2022.12.19 |
가운데 글자 가져오기 (0) | 2022.12.14 |
없는 숫자 더하기 (0) | 2022.12.14 |
음양 더하기 (0) | 2022.12.14 |