Java String Tokens

  • + 0 comments

    Easy Working for all test cases

    Scanner sc = new Scanner(System.in);
            
            String sent=sc.nextLine().trim();
            if(sent.length()>0){
                String [] words = sent.split("[ !,?._'@]+");
                System.out.println(words.length);
                for (String word:words)
                    System.out.println(word);
            }else{
                System.out.println(0);
            }
            sc.close();