You are viewing a single comment's thread. Return to all comments →
import java.util.*;
public class Solution {
public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); tokens(str); } public static void tokens(String s){ s = s.trim(); String[] words = s.split("\P{L}+");
if (s.length() == 0){ System.out.println(0); } else{ System.out.println(words.length); } for (String token:words){ System.out.println(token); }
} }
Seems like cookies are disabled on this browser, please enable them to open this website
Java String Tokens
You are viewing a single comment's thread. Return to all comments →
import java.util.*;
public class Solution {
public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); tokens(str); } public static void tokens(String s){ s = s.trim(); String[] words = s.split("\P{L}+");
} }