• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Allocates number within of array.

 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic