728x90
728x90
https://codingbat.com/prob/p199720
CodingBat Java Warmup-1 startOz
Given a string, return a string made of the first 2 chars (if present), however include first char only if it is 'o' and include the second only if it is 'z', so "ozymandias" yields "oz".
codingbat.com
= 문제 번역 =
문자열이 주어지면 처음 2개의 문자에서 첫 번째 문자는 'o'인 경우에는 o를 산출하고, 두 번째 문자는 'z'인 경우에는 z를 산출합니다.
만약 "ozymandias"가 주어진다면 첫 번째 문자와, 두 번째 문자를 같이 산출하여 "oz"를 산출합니다.
= 문제푸는 팁 =
= 해설 =
< 1 >
public String startOz(String str) {
String result = "";
if (str.length() >= 1 && str.charAt(0)=='o') {
result = result + str.charAt(0);
}
if (str.length() >= 2 && str.charAt(1)=='z') {
result = result + str.charAt(1);
}
return result;
}
728x90
'코딩테스트 > Coding Bat' 카테고리의 다른 글
[코딩뱃] [자바] Warmup - 1단계 : close10 문제 (0) | 2021.09.28 |
---|---|
[코딩뱃] [자바] Warmup - 1단계 : intMax 문제 (0) | 2021.09.27 |
[코딩뱃] [자바] Warmup - 1단계 : mixStart 문제 (0) | 2021.09.26 |
[코딩뱃] [자바] Warmup - 1단계 : delDel 문제 (0) | 2021.09.25 |
[코딩뱃] [자바] Warmup - 1단계 : loneTeen 문제 (2) | 2021.09.24 |