The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Returning an array

So this class take the value of endMiles and startMiles from the main class. Then it would calculate the distance by subtracing the startMiles from endMiles then returning the value of distanceV(This is the variable I use). As you can see I have a method to return the value of distanceV, this work perfectly fine but I'm calculating more than one distance so I want to put all the distanceV into an array. I have two method to put the distanceV to an array but when I return it and try to print it in the main method, it give me some random characters. Thanks

Re: Returning an array

So instead of making the array in the outer class, I decided to make the array in the main method class.(I haven't learn the toString yet so can't used it). Here is what I have. Is it possible to put any of this: - in the outer class ( The class in my orignal post) instead of the main? Thanks

It print out perfectly what I wanted, but I wanted this part of the code: - To be in the AnnualFuelUse class (My orignal post) instead of the main class. It is appropriate to have this part of the code in the main class instead of the AnnualFuelUse? I thought the main class suppose to be only used for calling on the method on the outside class ( I don't know what it called when one class is associated with another so I'll just call it outside class) Thanks

Re: Returning an array

Have you tried making it a method?

I don't know what rules you've been given about what goes in a "main" class and can't give you any advice.
I put the main() method in the class that has the code to be executed. I don't create a separate, special class that has only a main() method.

Re: Returning an array

I didn't want to spam the forum with a new thread, so hopefully it find for me to request help in this same one since it related.
I'm getting loss of precision for the following : - mpgA is a double but "i" is an int. So I get the loss of precision here "minMPG = mpgA[i]" How can I fix this? Thanks