It's not a secret anymore!*
The moose likes Java in General and the fly likes Allocates number within of array. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Allocates number within of array." Watch "Allocates number within of array." New topic
Author

Allocates number within of array.

Gustavo Siqueira
Ranch Hand

Joined: Jun 15, 2011
Posts: 97

Hello the all!
I want allocates number within of one array, see the program:



See the result:

Class1:
1
1
1
1
1
1

Or is, this allocating in all memory of array.

How to solved the problem ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

You're printing the first element (class1[0]) each time.

Also, your loop condition should be while(i < class1.length); so < and not <=. Arrays in Java start at 0 and go to the length - 1 inclusive, or the length exclusive.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: Allocates number within of array.