class Solution {
public String solution(String rny_string) {
String answer = "";
return answer;
}
}
해결법
방법 1
class Solution {
public String solution(String rny_string) {
String answer = rny_string.replaceAll("m","rn");
return answer;
}
}
방법 2
class Solution {
public String solution(String rny_string) {
String answer = "";
for (int i = 0; i < rny_string.length(); i++){
char current = rny_string.charAt(i);
if (current == 'm'){
answer += "rn";
} else {
answer += current;
}
}
return answer;
}
}
방법 3
class Solution {
public String solution(String rny_string) {
String answer = rny_string;
String[] arr = answer.split("");
for (int i = 0 ; i <= arr.length - 1; i++) {
if (arr[i].equals("m")) {
arr[i] = "rn";
}
}
answer = String.join("",arr);
return answer;
}
}
- String.join() 은 Java 8에서 추가된 메소드
- String.join("추가할 문자", "대상 list")
- String.join("추가할 문자", "대상 Array")
참고: Java 8 String join
rny_string Lv. 0