Skip to content

Commit fdc48cb

Browse files
Updated syntax / whitespace
1 parent 0e48afc commit fdc48cb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Misc/CountChar.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public static void main(String[] args) {
1717

1818
System.out.println("There are " + CountCharacters(str) + " characters.");
1919
}
20-
21-
22-
20+
2321
/**
2422
* @param str: String to count the characters
2523
*
@@ -30,12 +28,15 @@ public static int CountCharacters(String str) {
3028

3129
int count = 0;
3230

33-
if(str.isEmpty() || str == null)
34-
return -1;
31+
if(str == "" || str == null) //Exceptions
32+
{
33+
return 0;
34+
}
3535

36-
for(int i = 0; i < str.length(); i++)
37-
if(!Character.isWhitespace(str.charAt(i)))
36+
for(int i = 0; i < str.length(); i++) {
37+
if(!Character.isWhitespace(str.charAt(i))) {
3838
count++;
39+
}}
3940

4041
return count;
4142
}

0 commit comments

Comments
 (0)