Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CountAllWords {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String input = in.nextLine();
- input = input.replaceAll("\\W+", " ");
- String[] words = input.split(" ");
- int count = 0;
- for (String string : words) {
- count++;
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment