Skip to content

The code was very verbose. #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions Others/CountChar.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@


/**
* @author Kyler Smith, 2017
* @author blast314
* <p>
* Implementation of a character count.
* (Slow, could be improved upon, effectively O(n).
* Counts the number of characters in the text.
*/

public class CountChar {
Expand All @@ -24,21 +23,8 @@ public static void main(String[] args) {
* @param str: String to count the characters
* @return int: Number of characters in the passed string
*/

private static int CountCharacters(String str) {

int count = 0;

if (str == "" || str == null) {
return 0;
}

for (int i = 0; i < str.length(); i++) {
if (!Character.isWhitespace(str.charAt(i))) {
count++;
}
}

return count;
str = str.replaceAll("\\s","");
return str.length();
}
}