We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0e48afc commit fdc48cbCopy full SHA for fdc48cb
Misc/CountChar.java
@@ -17,9 +17,7 @@ public static void main(String[] args) {
17
18
System.out.println("There are " + CountCharacters(str) + " characters.");
19
}
20
-
21
22
+
23
/**
24
* @param str: String to count the characters
25
*
@@ -30,12 +28,15 @@ public static int CountCharacters(String str) {
30
28
31
29
int count = 0;
32
33
- if(str.isEmpty() || str == null)
34
- return -1;
+ if(str == "" || str == null) //Exceptions
+ {
+ return 0;
+ }
35
36
- for(int i = 0; i < str.length(); i++)
37
- if(!Character.isWhitespace(str.charAt(i)))
+ for(int i = 0; i < str.length(); i++) {
+ if(!Character.isWhitespace(str.charAt(i))) {
38
count++;
39
+ }}
40
41
return count;
42
0 commit comments