File tree 1 file changed +4
-18
lines changed
1 file changed +4
-18
lines changed Original file line number Diff line number Diff line change 4
4
5
5
6
6
/**
7
- * @author Kyler Smith, 2017
7
+ * @author blast314
8
8
* <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.
11
10
*/
12
11
13
12
public class CountChar {
@@ -24,21 +23,8 @@ public static void main(String[] args) {
24
23
* @param str: String to count the characters
25
24
* @return int: Number of characters in the passed string
26
25
*/
27
-
28
26
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 ();
43
29
}
44
30
}
You can’t perform that action at this time.
0 commit comments