-
Code Manipulation
There are numerous functions I have to make for this project at school. Here is one of them:
int charCount(String[]) - Takes an array of lines from a file. Returns the total number of characters (non-white space) in a file. I suggest examining the Character class in the Java API. There is a method you can use that will make this very easy.
I found the method called .isWhiteSpace()
Here is my function:
Code:
//FIX: COUNTING SPACES FOR SOME REASON
public static int charCount(String [] array){
int counter=0;
for(int i=0; i<array.length; i++){
for(int i2=0; i2<array[i].length(); i2++){
if(!(Character.isWhitespace(i2)))
{
counter++;
}
}
}
return counter;
}
For some reason, this function counts white spaces. I've tested it with text in a txt file. Does anyone know whats wrong? I can't seem to figure out what could possibly be causing this to happen.
-
Re: Code Manipulation
What have you done to debug it? Try putting in print statements to see what is actually being checked in the if.