File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes assigning a value the same as an index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "assigning a value the same as an index" Watch "assigning a value the same as an index" New topic

assigning a value the same as an index

Stephen Barrow

Joined: Mar 03, 2004
Posts: 13
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');
Adam Brown

Joined: Jan 08, 2004
Posts: 11
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

Joined: Oct 02, 2003
Posts: 11955

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.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sever oon
Ranch Hand

Joined: Feb 08, 2004
Posts: 268
Yea, I can only assume that you're trying to get an array that looks like { 0, 1, 2, ..., 98, 99 }. To do that:

I agree. Here's the link:
subject: assigning a value the same as an index
It's not a secret anymore!