Java String Tokens

윤지현·2025년 3월 10일
0

HackerRank[Java]

목록 보기
12/57
  • 문제
  • 정답
import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        
        String[] outStrings = s.split("[^a-zA-Z]+");
        
        int count = 0;
        for (String word : outStrings) {
            if (!word.isEmpty()) {
                count++;
            }
        }
        
        System.out.println(count);
        
        for (String word : outStrings) {
            if (!word.isEmpty()) { 
                System.out.println(word);
            }
        }
        
        scan.close();
    }
}
  • 결과
profile
첫 시작

0개의 댓글