This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes getting values from for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getting values from for loop" Watch "getting values from for loop" New topic
Author

getting values from for loop

Reshma Reddy
Ranch Hand

Joined: Dec 21, 2006
Posts: 197
Hi All,

In my for loop I am getting 10 values,this values return type is double, I want to assign each values(1-10) to individual variable(Ex:d1 is:23.345,d2 is:45.988,d3 is:87.098....etc).Can any one help me how Can I assign this.



regards,
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Use an array of ten doubles:



[Jess in Action][AskingGoodQuestions]
Reshma Reddy
Ranch Hand

Joined: Dec 21, 2006
Posts: 197
Hi hill,

thanks for your reply


regards,
Reshma Reddy
Ranch Hand

Joined: Dec 21, 2006
Posts: 197
Hi hill,

how to assign this 10 values to 10different double values.
Ex: double d1,d2,d3....
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10175
    
    8

Recommended reading
http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

Are you trying to dynamically name your variables? i.e. if you have 10 doubles, you want variables named d1 through d10, but if you had 20 you'd want d1 through d20?

The short answer is - you can't. and there is no reason to. giving a variable a name is really only for the author's convenience. If they are being generated dynamically, the author will never see them, so they serve no point.

Seriously, use an array.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
 
subject: getting values from for loop
 
Similar Threads
Question about string immutable
Dice probability program, using nested loops.
Returning A List Of Variables From A Folder Of Documents And Returning Them Into A New Document
Can not Populate the form on combo box change
How to call procedure in JDBC