포스트

공백으로 구분하기1

https://school.programmers.co.kr/learn/courses/30/lessons/181869

문제

  • 문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;

class Solution {
    public static String[] solution(String my_string) {
        String[] words = my_string.split(" "); // 공백을 기준으로 단어 분리

        return words;
    }
    
     public static void main(String[] args) {
        String my_string1 = "i love you";
        String my_string2 = "programmers";

        String[] result1 = solution(my_string1);
        String[] result2 = solution(my_string2);

        // 결과 출력
        System.out.println("Result 1: ");
        for (String word : result1) {
            System.out.println(word);
        }

        System.out.println("\nResult 2: ");
        for (String word : result2) {
            System.out.println(word);
        }
    }
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.