Results 1 to 2 of 2
  1. #1
    danthegreat is offline Member
    Join Date
    Sep 2011
    Location
    Washington DC
    Posts
    51
    Rep Power
    0

    Default 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:
    Java 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.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default 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.

Similar Threads

  1. String manipulation
    By lakshmibvaraprasad in forum New To Java
    Replies: 4
    Last Post: 07-16-2011, 01:41 PM
  2. String manipulation
    By i4ba1 in forum Advanced Java
    Replies: 2
    Last Post: 12-22-2010, 08:53 AM
  3. textField manipulation
    By Bogdan in forum Advanced Java
    Replies: 3
    Last Post: 12-15-2010, 02:54 AM
  4. Image Manipulation
    By sh100 in forum New To Java
    Replies: 0
    Last Post: 11-03-2009, 10:18 AM
  5. Image manipulation.
    By ambikark in forum Advanced Java
    Replies: 0
    Last Post: 10-15-2008, 01:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •