diff --git a/Others/countwords.java b/Others/countwords.java index 30806e13f..a93aa1a33 100644 --- a/Others/countwords.java +++ b/Others/countwords.java @@ -18,8 +18,8 @@ import java.util.Scanner; input.close(); } - public static int wordCount(String s){ - if(s.isEmpty() || s == null) return -1; + private static int wordCount(String s){ + if(s.isEmpty() || s == null) return 0; return s.trim().split("[\\s]+").length; }