Algorithm
[프로그래머스][JAVA] 수박수박수박수박수
밍맹030
2020. 1. 6. 15:28
728x90
문제 설명
길이가 n이고, 수박수박수박수....와 같은 패턴을 유지하는 문자열을 리턴하는 함수, solution을 완성하세요. 예를들어 n이 4이면 수박수박을 리턴하고 3이라면 수박수를 리턴하면 됩니다.
제한 조건
- n은 길이 10,000이하인 자연수입니다.

728x90
1
2
3
4
5
6
7
8
9
10
11
12
|
class Solution {
public String solution(int n) {
String answer = "";
for(int i=0; i<n/2; i++){
answer+="수박";
}
if(n%2!=0){
answer+="수";
}
return answer;
}
}http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/courses/30/lessons/12922
728x90