File tree Expand file tree Collapse file tree 1 file changed +4
-18
lines changed
Expand file tree Collapse file tree 1 file changed +4
-18
lines changed Original file line number Diff line number Diff line change 44
55
66/**
7- * @author Kyler Smith, 2017
7+ * @author blast314
88 * <p>
9- * Implementation of a character count.
10- * (Slow, could be improved upon, effectively O(n).
9+ * Counts the number of characters in the text.
1110 */
1211
1312public class CountChar {
@@ -24,21 +23,8 @@ public static void main(String[] args) {
2423 * @param str: String to count the characters
2524 * @return int: Number of characters in the passed string
2625 */
27-
2826 private static int CountCharacters (String str ) {
29-
30- int count = 0 ;
31-
32- if (str == "" || str == null ) {
33- return 0 ;
34- }
35-
36- for (int i = 0 ; i < str .length (); i ++) {
37- if (!Character .isWhitespace (str .charAt (i ))) {
38- count ++;
39- }
40- }
41-
42- return count ;
27+ str = str .replaceAll ("\\ s" ,"" );
28+ return str .length ();
4329 }
4430}
You can’t perform that action at this time.
0 commit comments