Results 1 to 18 of 18
Like Tree1Likes
  • 1 Post By doWhile

Thread: How to count records WITHOUT an array?

  1. #1
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default How to count records WITHOUT an array?

    I have been looking for a method that will perform this for me but I just can't seem to do so, so I figured I'll ask and see if anybody has suggestions on how to perform this?(WITHOUT an array)

  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

    I don't believe there are any methods for counting words. Doing this yourself with charAt or substring should be relatively easy.

  3. #3
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    What about whole objects?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by teekei View Post
    What about whole objects?
    What about them? What does this statement mean and how does it apply to your original question? And what do you mean by "records"? Are you asking about using a database?

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Define record...an object? A collection of objects? A database entry? A file? Words in a file? Your question is not detailed enough for a detailed answer. What exactly do you want to count?

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

    Default

    I'm not exactly sure what you mean, a string is an Object.

  7. #7
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    Like one whole record is equal to one object... would you count that with a while loop? I'm confused..

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by teekei View Post
    Like one whole record is equal to one object... would you count that with a while loop? I'm confused..
    Your confused? You're asking without providing us with any useful information that would allow anyone to answer it, as if we can read your mind. I think it's safe to say that we're confused more.

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

    Default

    Sure. You should just write a method that looks like this
    Java Code:
    public int countWords(String s)
    And then think how you would repeatedly test the next character.

  10. #10
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    Yes I mean like a database...
    Example:
    StudentName StudentID StudentGpa <---- That would be equal to one record.

  11. #11
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    So how would you count one record after the other? Would a while loop be sufficient enough to pull this off?

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

    Default

    Try and see what you can come up with.

  13. #13
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    Java Code:
    	public int countRecords()
    	{
    		int recordCounter;
    
    		while( recordCounter <= classCode.length)
    		{
    			recordCounter++;
    		}
    		int gpaAverage = recordCounter/classCode.length;
    	}
    This is what I have come up with so far...

  14. #14
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    It didn't compile, here are the errors
    Java Code:
    F:\PA2\GpaRecord.java:111: int cannot be dereferenced
    		while( recordCounter <= classCode.length)
    		                                 ^
    F:\PA2\GpaRecord.java:115: int cannot be dereferenced
    		int gpaAverage = recordCounter/classCode.length;
    		                                        ^
    2 errors

  15. #15
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Your questions are coming out of left field, with absolutely no context whatsoever. We can't help you if you do not provide this context. If you want help, I recommend you read, study, and following the guidelines in the following link: How To Ask Questions The Smart Way
    Fubarable likes this.

  16. #16
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by doWhile View Post
    Your questions are coming out of left field, with absolutely no context whatsoever. We can't help you if you do not provide this context. If you want help, I recommend you read, study, and following the guidelines in the following link: How To Ask Questions The Smart Way
    I apologize for your lack of understanding towards the question I asked. I'll be sure to read this so I can avoid confusing you again...Again, I apologize.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    As has been asked.
    What are you counting?
    You talk about "records", but that's a meaningless term in Java, outside of certain frameworks.

    So what is a record?
    Where are these records?
    They are presumably not in a array since you say you can't use an array to do this.

  18. #18
    karno is offline Member
    Join Date
    Mar 2010
    Posts
    16
    Rep Power
    0

    Default

    can you explain what problem do you want to solve spesificly??

Similar Threads

  1. Replies: 14
    Last Post: 01-22-2011, 02:36 PM
  2. How do I count empty spaces in a byte array?
    By nessa203 in forum New To Java
    Replies: 13
    Last Post: 01-11-2010, 05:46 PM
  3. insert records
    By rudravaram in forum JDBC
    Replies: 3
    Last Post: 01-03-2010, 05:54 PM
  4. i can do count, but having problem with array
    By judy318 in forum New To Java
    Replies: 4
    Last Post: 10-29-2009, 09:23 PM
  5. Array count number Occurances
    By gwithey in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 08:34 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
  •