Java String Tokens

  • + 0 comments

    Solved

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        // Write your code here.
        String[] arrayTemp = s.split("[ !,?._'@]+");
        StringBuffer strResult = new StringBuffer();
        int count = 0;
        for(int i = 0; i < arrayTemp.length; i++){
            if(arrayTemp[i].matches("[A-Za-z]+")){
                count++;
                strResult.append(arrayTemp[i]+"\n");
            }
        }
        System.out.println(count+"\n"+strResult);    
    
        scan.close();
    }