This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple variables in a loop

 
Brandon Chamberlain
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of trying to explain all the different conditions I've tried, maybe there's a much simpler approach to the following situation:

I want to be able to input a unknown number of values, ending the list with the value 999
I then want it to take the difference of each consecutive value.
Finally, output these differences in a list.

Example

Input:
10.5
12.05
13.25
21
7
999

Output:
1.55
1.20
7.75
-14

I do not want the outputs list mixed in the inputs list... I want all the inputs listed first (as they're entered - an unknown number of inputs), the list ending with 999.
Followed by a list of outputs...
Any suggestions?

p.s. the equations and code is simple enough, just the formatting of getting all the inputs first then listing all the outputs is where I'm stuck.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
collect all your inputs into something like an Arraylist (which will grow as big as you need it).

once the user inputs 999 (don't collect that value), just iterate through the list and do the subtraction.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to javaranch Brandon
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic