import java.util.ArrayList;
import java.util.Arrays;
public class Sample {
public static void main(String[] args) {
ArrayList<String> pitches = new ArrayList<>(Arrays.asList("138", "129", "142"));
String result = "";
for (int i = 0; i < pitches.size(); i++) {
result += pitches.get(i);
result += ","; // 콤마를 추가한다.
}
result = result.substring(0, result.length() - 1); // 마지막 콤마는 제거한다.
System.out.println(result); // 138,129,142 출력
}
}
- 우선, 결과를 보고자 하는 것은 result이다
- 그 result 값을 담을 plate를 만든다(프로그래밍에서는 변수에 새 값을 덮어씌우는 경향이 있음) // 만들때 자료형도 항상 정의
- result를 빼오려면, 기존에 나온 제네릭스인 pitches에서 정의되어야 한다(waterfall image)
- 그래서 for문의 조건 및 statement 모두 pitches기반으로 작성
- 마지막 콤마를 제거하는 부분에서는, result string이 완성되어 있으므로 result에서 마지막 result를 정의한다
'Hard deck > embodying workflow' 카테고리의 다른 글
코드 flow 해석 / 변경 (0) | 2022.05.07 |
---|---|
기본 모델링 (0) | 2022.02.09 |
구현 방식 (0) | 2022.02.04 |