Results 1 to 9 of 9
- 07-07-2011, 04:28 PM #1
How to get a float out of an for loop?
I have this code:
But how do I get the 'massa' out of this for loop?Java Code:for (int i = 0; i < peptide_zelfInfo.length(); i++) { String ss = peptide_zelfInfo.substring(i, i +1); float mass = y.get(ss); float massa = mass + y.get(ss); System.out.println(massa); }
- 07-07-2011, 04:32 PM #2
Member
- Join Date
- Jul 2011
- Posts
- 7
- Rep Power
- 0
I don't understand your question but you can't define a variable inside a loop, so you should do it like this:
Java Code:String ss = ""; float mass = 0.0; float massa = 0.0; for (int i = 0; i < peptide_zelfInfo.length(); i++) { ss = peptide_zelfInfo.substring(i, i +1); mass = y.get(ss); massa = mass + y.get(ss); System.out.println(massa); }
- 07-07-2011, 04:40 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
It's not just one float value but it's one for every loop iteration. Please rethink your question and ask again ... possible answers could be a List of floats, one of the added to the List per loop iteration. At the end the entire List could be returned; but that is just guessing ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-07-2011, 04:42 PM #4
I would like to have the 'massa' used outside the for loop.
Too print in in my XML file.
- 07-07-2011, 05:07 PM #5
There were two choices offered. Did either of those solve your problem?
If not explain what you want that is different from what those two solutions offered.
- 07-07-2011, 05:13 PM #6
I am trying a list right now. :)
- 07-07-2011, 05:24 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 07-08-2011, 01:27 AM #8
- 07-08-2011, 07:43 PM #9
Similar Threads
-
FloatBuffer and 'put( float[] src )'
By maxkiva in forum New To JavaReplies: 4Last Post: 08-08-2010, 11:56 AM -
Error in float value
By JMaste in forum New To JavaReplies: 5Last Post: 07-11-2010, 04:08 PM -
string to float
By Sungron in forum New To JavaReplies: 3Last Post: 02-02-2010, 09:23 AM -
Float vs. Double
By javanub in forum New To JavaReplies: 1Last Post: 11-23-2008, 12:11 PM -
Class float
By Peter in forum New To JavaReplies: 1Last Post: 07-08-2007, 01:17 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks