my dog learned polymorphism*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 19552
    
  16

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.
 
Similar Threads
something more about arrays
Array problem
Wanted some help about arrays
Accessing component from main class.... Help!
and yet another recursive problem