Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 No pointers...hmm...
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Martin




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: 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!
rizzix




PostPosted: 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;
Martin




PostPosted: Thu Nov 04, 2004 4:09 pm   Post subject: (No subject)

Yeah, nevermind, it was a dumb question. I'm just slow lately.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: