Computer Science Canada array out of bounds |
Author: | cool dude [ Wed Jul 26, 2006 2:01 pm ] | ||
Post subject: | array out of bounds | ||
i made this sample program test however i'm getting an array out of bounds error and i can't seem to fix it.
|
Author: | rizzix [ Wed Jul 26, 2006 2:30 pm ] | ||
Post subject: | |||
3 not 2. It's the length not the last index. |
Author: | [Gandalf] [ Wed Jul 26, 2006 3:53 pm ] | ||
Post subject: | |||
So to prevent things like this from happening in the future, use num.length instead of a constant number which really has nothing to do with your array. The loop would become:
Though this brings up the question of... Do you not understand arrays yet, or did you simply overlook this? Arrays are much more important to understand than BigIntegers. |
Author: | cool dude [ Thu Jul 27, 2006 11:09 am ] |
Post subject: | |
thanks. one more question. how would you get the length of the number of digits in the array. for example if the number was 1234 it would tell me that its 4 digits long. i tried using lenght(); but it doesn't work. it says, "cannot resolve symbol method length()" |
Author: | cool dude [ Thu Jul 27, 2006 11:23 am ] | ||
Post subject: | |||
here's my code:
|
Author: | wtd [ Thu Jul 27, 2006 11:42 am ] |
Post subject: | |
Where does the method "length" come from? |
Author: | cool dude [ Thu Jul 27, 2006 12:08 pm ] | ||
Post subject: | |||
wtd wrote: Where does the method "length" come from?
what do you mean where it comes from? i've always been able to do something like :
|
Author: | wtd [ Thu Jul 27, 2006 12:24 pm ] |
Post subject: | |
Back to Java 101. All methods live inside classes. Which class does the length method live in? |
Author: | cool dude [ Thu Jul 27, 2006 12:34 pm ] |
Post subject: | |
wtd wrote: Back to Java 101.
All methods live inside classes. Which class does the length method live in? oh i see. the string class. so now i have to convert the array to a string. but how? |
Author: | cool dude [ Thu Jul 27, 2006 1:03 pm ] |
Post subject: | |
just figured it out. thanks for the help |