mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 00:54:32 +08:00
Updated syntax / whitespace
This commit is contained in:
@ -17,9 +17,7 @@ public class CountChar {
|
|||||||
|
|
||||||
System.out.println("There are " + CountCharacters(str) + " characters.");
|
System.out.println("There are " + CountCharacters(str) + " characters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param str: String to count the characters
|
* @param str: String to count the characters
|
||||||
*
|
*
|
||||||
@ -30,12 +28,15 @@ public class CountChar {
|
|||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if(str.isEmpty() || str == null)
|
if(str == "" || str == null) //Exceptions
|
||||||
return -1;
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < str.length(); i++)
|
for(int i = 0; i < str.length(); i++) {
|
||||||
if(!Character.isWhitespace(str.charAt(i)))
|
if(!Character.isWhitespace(str.charAt(i))) {
|
||||||
count++;
|
count++;
|
||||||
|
}}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user