https://www.hackerrank.com/challenges/java-string-tokens/problem?isFullScreen=true
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().trim();
if(s.length() <= 0 ){
System.out.println("0");
}else{
// Write your code here.
String[] arr = null;
arr = s.split("[ !,?._'@]+");
System.out.println(arr.length);
for(int i=0; i < arr.length; i++){
System.out.println(arr[i]);
}
}
scan.close();
}
}
// Write your code here. 아래 부분만 작성했다가 tc보고
trim()추가하고
9번 tc가 input값이 아예없는 거 확인하고 s.length가 0일 때 추가함..
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#split-java.lang.String-
반응형
'HackerRank > JAVA' 카테고리의 다른 글
[작성중]Java Regex 2 - Duplicate Words (0) | 2024.01.19 |
---|---|
[못품]Java Regex (0) | 2024.01.17 |
Java Anagrams (0) | 2024.01.17 |
Java String Reverse (0) | 2024.01.17 |
Java Substring Comparisons (0) | 2024.01.17 |