No pointers...hmm...
Author |
Message |
Martin
![](http://www.compsci.ca/wiki/images/4/46/CanadianStickUp.jpg)
|
Posted: Thu Nov 04, 2004 3:59 pm Post subject: No pointers...hmm... |
|
|
Okay, I have a set of 5 objects, each of which is storing a number. I need to return the object associated with the lowest number. With C++, I could use a pointer, but how would I do this with Java? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Dan
![](http://wiki.compsci.ca/images/archive/3/3c/20100325043407!Danspic.gif)
|
Posted: Thu Nov 04, 2004 4:05 pm Post subject: (No subject) |
|
|
have u tryed just retruning the object? lol
ie. return objectName
or am i missing the point of your post? |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
![](images/spacer.gif) |
rizzix
|
Posted: Thu Nov 04, 2004 4:08 pm Post subject: (No subject) |
|
|
assuming you define a method for each object to retrive the value of the stored number as getNumber
then all you need to do is probably something like this (assuming that the 5 objects are in an array called objects and StoringObject is the name of the class that defines these objects)
code: | StoringObject obj = objects[0];
for (StoringObject o : objects)
if (obj.getNumber() < o.getNumber())
obj = o; |
|
|
|
|
|
![](images/spacer.gif) |
Martin
![](http://www.compsci.ca/wiki/images/4/46/CanadianStickUp.jpg)
|
Posted: Thu Nov 04, 2004 4:09 pm Post subject: (No subject) |
|
|
Yeah, nevermind, it was a dumb question. I'm just slow lately. |
|
|
|
|
![](images/spacer.gif) |
|
|