Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assigning a value the same as an index

 
Stephen Barrow
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I declare an array of double of size 100 to store point values of 100 students and assigns each student element a value same as its index (or subscript) number.
Would this code work?
student = new Student("John", 10, ,'M');
stu.add(student);
 
Adam Brown
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Going by your snippet of code, I'm pretty sure that you are creating a student object, passing in your specific arguments to the Student constructor, and then adding that student object to an array list. Are you trying to cycle through those objects and assign an index value to each? Would it be passed in as one of the arguments in the Student constructor? Your request is a bit vague in that respect...Is there anyway that you could clarify what you're looking to accomplish?
[ March 04, 2004: Message edited by: Adam Brown ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam is right... your question seems a little vague. but if this helps...
to declare an array of 100 doubles, you need to do this...

now you HAVE the array, but they're all initialized to 0.0
if you want each element to have the value of it's index, you'll need a loop... use indexArray.length as your bound, and you should be fine.
 
sever oon
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, I can only assume that you're trying to get an array that looks like { 0, 1, 2, ..., 98, 99 }. To do that:

sev
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic