We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b8b2938 commit e3dfdf2Copy full SHA for e3dfdf2
1 file changed
Others/CountChar.java
@@ -4,10 +4,9 @@
4
5
6
/**
7
- * @author Kyler Smith, 2017
+ * @author blast314
8
* <p>
9
- * Implementation of a character count.
10
- * (Slow, could be improved upon, effectively O(n).
+ * Counts the number of characters in the text.
11
*/
12
13
public class CountChar {
@@ -24,21 +23,8 @@ public static void main(String[] args) {
24
23
* @param str: String to count the characters
25
* @return int: Number of characters in the passed string
26
27
-
28
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;
+ str = str.replaceAll("\\s","");
+ return str.length();
43
}
44
0 commit comments