This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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: 19697
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Allocates number within of array.