Results 1 to 18 of 18
Thread: [SOLVED] Multiple return values
- 05-20-2009, 02:20 PM #1
- 05-20-2009, 03:26 PM #2
Directly, no. But you can return an array which can hold as many return values as you you want.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 05-20-2009, 03:55 PM #3
Thanks man!
- 05-22-2009, 11:04 AM #4
Hi, i tried using the array in return and it just worked fine BUT now i come across another problem where i get an error "non-static method cannot be referenced from a static context"
whats all this about coz i really dont understand why am getting this?
Best Regards
Frizy
- 05-22-2009, 11:15 AM #5
Hi,
Create an instance and call the method.
-Regards
RamyaRamya:cool:
- 05-25-2009, 08:31 AM #6
Hi pple,
Am trying to return an array but am not getting any value returned. I really dont know where i made a mistake:confused:
below is my code:
Java Code:public int iodineChange(double IFY, double MFX, double IDC, double NF){ double equilibriumIod = equilibriumIodine(IFY,MFX,IDC); DecimalFormat myVal = new DecimalFormat("0.00E0"); /*---------------------------------------------------------------------*/ /*Formulae: I(t+dt) = I(t) * exp(-IDC * dt) + I(eq) * */ /* (1 - exp(-IDC * dt)) */ /*---------------------------------------------------------------------*/ int rCount = Xenon.getRowCount(); int arraySize = rCount; int[] iodine_t = new int[arraySize]; for (int i = 0; i < rCount; i++) { String time = (String)Xenon.getValueAt(i,0); if (time == null){ break; } double time_hrs = Double.parseDouble(time); double time_mins = (time_hrs*60)/300; double term1 = IDC * time_mins * (-1.0); term1 = Math.exp(term1); double Iod = 1.0 - term1; Iod = Iod * equilibriumIod; //calculates instantaneous iodine concentration String pr_t = (String)Xenon.getValueAt(i, 1); Double powerlevel = Double.parseDouble(pr_t); double val = IFY; val = val * MFX; val = val / IDC; val = (val * NF * powerlevel); Iod = Iod + (term1 * val); Iod = iodine_t[arraySize-1]; Temp.setValueAt(myVal.format(Iod),i,2); } System.out.println("IODINE CHANGE : "+iodine_t); return iodine_t[arraySize-1]; }
Any help will be highly appriciated
Thank you
- 05-25-2009, 09:30 AM #7
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Not sure how much of what you want this will fix, but here goes...
1. change the int in the first line to int[]
2. Change the return statement to return iodine_t
The second line of code seems fishy to me... though I may just be missing something.
BTW... This may not work. We will need to see more code, and an SSCCE would be good if the code is too long to be posted in its entirety (include in a .zip file or .jar(though I don't know if .jar is accepted))
If for any reason the code cannot be attached or posted, at least explain what Xenon is.If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 05-25-2009, 10:08 AM #8
ok, this is just a method that reads some values from a table called xenon and does calculation on each value read from the table.
gets the number of rows in the table xenon.Java Code:int rCount = Xenon.getRowCount();
xenon table contains two columns-time and power level
i want the array size to as big as the number of rows in the table coz the they keep on varrying depending on user input.
for each row some computation is done and now my problem is returning the all the results obtained in each row from the calculation.
i hope i am clear enough
Best Regards,
manfizy
- 05-25-2009, 10:23 AM #9
Hi,
Where you are using the array "iodine_t" .You have to write the comments in sucha a way that people should understanbd the code flow.
U have declared the array with the size of the table.But u are not using it.
Clearly explain what u are doing and what u want to return so that we can give quick solution for u.
-Regards
RamyaRamya:cool:
- 05-25-2009, 10:32 AM #10
Yes, i have declared tha array to be the size of the table.
If you have noticed am using loop to do computation on each row up to the last value in the row. As stated above i want to add the result of the calculation done in each row to the array and finally return the array.
OMG!!just tel me you understand what am doing this time round :-)
Best Regards,
manfizy
- 05-25-2009, 10:51 AM #11
I have added afew comments in the code and i hope its understandable this time round. In short i want the to add Iod to the array and the loop repeats untill the last value in the table.Java Code:public int iodineChange(double IFY, double MFX, double IDC, double NF){ double equilibriumIod = equilibriumIodine(IFY,MFX,IDC); DecimalFormat myVal = new DecimalFormat("0.00E0"); /*---------------------------------------------------------------------*/ /*Formulae: I(t+dt) = I(t) * exp(-IDC * dt) + I(eq) * */ /* (1 - exp(-IDC * dt)) */ /*---------------------------------------------------------------------*/ int rCount = Xenon.getRowCount(); int arraySize = rCount; int[] iodine_t = new int[arraySize];//declared array size to be the same as table size for (int i = 0; i < rCount; i++) { String time = (String)Xenon.getValueAt(i,0); if (time == null){ break; } double time_hrs = Double.parseDouble(time); double time_mins = (time_hrs*60)/300; double term1 = IDC * time_mins * (-1.0); term1 = Math.exp(term1); double Iod = 1.0 - term1; Iod = Iod * equilibriumIod; //calculates instantaneous iodine concentration String pr_t = (String)Xenon.getValueAt(i, 1); Double powerlevel = Double.parseDouble(pr_t); double val = IFY; val = val * MFX; val = val / IDC; val = (val * NF * powerlevel); Iod = Iod + (term1 * val); //Add the value of Iod to the array iodine_t Iod = iodine_t[arraySize-1]; Temp.setValueAt(myVal.format(Iod),i,2); } System.out.println("IODINE CHANGE : "+iodine_t); return iodine_t[arraySize-1]; }
After all this is done, i want to return the array so that i can use the result in another method.
best regards,
manfizy
- 05-25-2009, 11:09 AM #12
how come my posts are not visible???
- 05-25-2009, 11:14 AM #13
iam able to see the post and given reply.Just refresh the page and try once.
Ramya:cool:
- 05-25-2009, 11:14 AM #14
I have added afew comments in the code to make it understandable.Java Code:public int iodineChange(double IFY, double MFX, double IDC, double NF){ double equilibriumIod = equilibriumIodine(IFY,MFX,IDC); DecimalFormat myVal = new DecimalFormat("0.00E0"); /*---------------------------------------------------------------------*/ /*Formulae: I(t+dt) = I(t) * exp(-IDC * dt) + I(eq) * */ /* (1 - exp(-IDC * dt)) */ /*---------------------------------------------------------------------*/ int rCount = Xenon.getRowCount(); int arraySize = rCount; //declare array size to be same as table size int[] iodine_t = new int[arraySize]; for (int i = 0; i < rCount; i++) { String time = (String)Xenon.getValueAt(i,0); if (time == null){ break; } double time_hrs = Double.parseDouble(time); double time_mins = (time_hrs*60)/300; double term1 = IDC * time_mins * (-1.0); term1 = Math.exp(term1); double Iod = 1.0 - term1; Iod = Iod * equilibriumIod; //calculates instantaneous iodine concentration String pr_t = (String)Xenon.getValueAt(i, 1); Double powerlevel = Double.parseDouble(pr_t); double val = IFY; val = val * MFX; val = val / IDC; val = (val * NF * powerlevel); Iod = Iod + (term1 * val); //Add Iod to the Array Iod = iodine_t[arraySize-1]; Temp.setValueAt(myVal.format(Iod),i,2); } System.out.println("IODINE CHANGE : "+iodine_t); return iodine_t[arraySize-1]; }
Inshort all i want is to add Iod to tha array iodine_t until the loop is terminated.
After that i want to return the array
- 05-25-2009, 11:35 AM #15
Hi,
Go thru the modified code.
Java Code:public int iodineChange(double IFY, double MFX, double IDC, double NF){ double equilibriumIod = equilibriumIodine(IFY,MFX,IDC); DecimalFormat myVal = new DecimalFormat("0.00E0"); /*---------------------------------------------------------------------*/ /*Formulae: I(t+dt) = I(t) * exp(-IDC * dt) + I(eq) * */ /* (1 - exp(-IDC * dt)) */ /*---------------------------------------------------------------------*/ int rCount = Xenon.getRowCount(); int arraySize = rCount; //declare array size to be same as table size int[] iodine_t = new int[arraySize]; for (int i = 0; i < rCount; i++) { String time = (String)Xenon.getValueAt(i,0); if (time == null){ break; } double time_hrs = Double.parseDouble(time); double time_mins = (time_hrs*60)/300; double term1 = IDC * time_mins * (-1.0); term1 = Math.exp(term1); double Iod = 1.0 - term1; Iod = Iod * equilibriumIod; //calculates instantaneous iodine concentration String pr_t = (String)Xenon.getValueAt(i, 1); Double powerlevel = Double.parseDouble(pr_t); double val = IFY; val = val * MFX; val = val / IDC; val = (val * NF * powerlevel); Iod = Iod + (term1 * val); [B][COLOR="SeaGreen"]//Add Iod to the Array //Commented this below line. //Iod = iodine_t[arraySize-1]; //Added the Iod to array iodine_t[i] = Iod;[/COLOR][/B] Temp.setValueAt(myVal.format(Iod),i,2); } [B][COLOR="SeaGreen"]//The below line prints the address only so iam commenting //System.out.println("IODINE CHANGE : "+iodine_t);[/COLOR][/B] //Added this for loop for printing array value. for(int j= 0; j< iodine_t.length;j++) { System.out.println("Array value "+j + " ----> "+iodine_t[j]); } return iodine_t[arraySize-1]; }Last edited by RamyaSivakanth; 05-25-2009 at 11:37 AM.
Ramya:cool:
- 05-25-2009, 11:57 AM #16
thank you very much. it worked properly
now what i dont know is how to write the return statement.
how can i write it???
bets regards
manfizy:)
- 05-25-2009, 12:01 PM #17
Just change the signature of the method and return statement as array object.go thru the change below.Please have a look at Javadoc for clear understanding of arrays .
Java Code:[B][COLOR="DarkGreen"]public int[] iodineChange(double IFY, double MFX, double IDC, double NF)[/COLOR][/B]{ double equilibriumIod = equilibriumIodine(IFY,MFX,IDC); DecimalFormat myVal = new DecimalFormat("0.00E0"); /*---------------------------------------------------------------------*/ /*Formulae: I(t+dt) = I(t) * exp(-IDC * dt) + I(eq) * */ /* (1 - exp(-IDC * dt)) */ /*---------------------------------------------------------------------*/ int rCount = Xenon.getRowCount(); int arraySize = rCount; //declare array size to be same as table size int[] iodine_t = new int[arraySize]; for (int i = 0; i < rCount; i++) { String time = (String)Xenon.getValueAt(i,0); if (time == null){ break; } double time_hrs = Double.parseDouble(time); double time_mins = (time_hrs*60)/300; double term1 = IDC * time_mins * (-1.0); term1 = Math.exp(term1); double Iod = 1.0 - term1; Iod = Iod * equilibriumIod; //calculates instantaneous iodine concentration String pr_t = (String)Xenon.getValueAt(i, 1); Double powerlevel = Double.parseDouble(pr_t); double val = IFY; val = val * MFX; val = val / IDC; val = (val * NF * powerlevel); Iod = Iod + (term1 * val); //Add Iod to the Array //Commented this below line. //Iod = iodine_t[arraySize-1]; //Added the Iod to array iodine_t[i] = Iod; Temp.setValueAt(myVal.format(Iod),i,2); } //The below line prints the address only so iam commenting //System.out.println("IODINE CHANGE : "+iodine_t); for(int j= 0; j< iodine_t.length;j++) { System.out.println("Array value "+j + " ----> "+iodine_t[j]); } [B][COLOR="DarkGreen"]return iodine_t;[/COLOR][/B] }Ramya:cool:
- 05-25-2009, 12:07 PM #18
Similar Threads
-
to retrieve multiple values from html page through jsp
By raghu9198 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 02-17-2009, 02:43 PM -
accessing return values from another class
By moaxjlou in forum New To JavaReplies: 3Last Post: 10-31-2008, 02:25 AM -
Using functions that return values?
By Megapixelz in forum New To JavaReplies: 1Last Post: 04-30-2008, 04:07 AM -
how to return values from hashmap
By oregon in forum New To JavaReplies: 2Last Post: 08-01-2007, 04:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks