Computer Science Canada Returning an array from a method to the main program |
Author: | LOL123 [ Sat Apr 24, 2010 10:19 pm ] | ||||
Post subject: | Returning an array from a method to the main program | ||||
Hello for this program I need to read in 12 incomes from file in the main program then in a method I have to store all of the incomes in an array. I have done this but I dont know how to return an array
Here is my method...
When I run the program I get this error File: I:\usB\ICS\ArrayPrac 1 REDO\array_Methods.java [line: 12] Error: incompatible types found : double[] required: java.lang.String Thanks for checking ![]() |
Author: | Insectoid [ Sat Apr 24, 2010 10:55 pm ] | ||
Post subject: | RE:Returning an array from a method to the main program | ||
Or something like that. |
Author: | LOL123 [ Sat Apr 24, 2010 11:32 pm ] |
Post subject: | RE:Returning an array from a method to the main program |
Making the array a string wont work it needs to be a double. Since I am dealing with money in this program. |
Author: | Barbarrosa [ Sun Apr 25, 2010 1:43 am ] |
Post subject: | Re: Returning an array from a method to the main program |
All you've got wrong is your return type. Replace "String initialize" with "double[] initialize" or "Double[] initialize". You're not going to get any output, though... you need System.out.print() or some kind of output stream for that. |
Author: | wtd [ Sun Apr 25, 2010 9:22 pm ] |
Post subject: | Re: RE:Returning an array from a method to the main program |
LOL123 @ Sun Apr 25, 2010 12:32 pm wrote: Making the array a string wont work it needs to be a double. Since I am dealing with money in this program.
Epic fail. Money should never be modeled as a floating point number. If you need further instruction, watch Office Space. |
Author: | LOL123 [ Sun Apr 25, 2010 10:16 pm ] |
Post subject: | RE:Returning an array from a method to the main program |
Im sorry wtd, I didnt choose how the program needs to be completed Im just following instructions from my teacher. |
Author: | DemonWasp [ Mon Apr 26, 2010 2:07 pm ] |
Post subject: | RE:Returning an array from a method to the main program |
wtd is just referring to problems representing money with the limited floating-point representations we generally use. Instead, money is usually modeled with integers, with the units in cents. However, for this assignment, the compile error you're getting is that the method's listed return type is "String", but you want it to be "double[]". Try changing the return type to "double[]" go from there. |