Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2009, 03:50 AM
Member
 
Join Date: Sep 2009
Posts: 10
Rep Power: 0
Kaito is on a distinguished road
Default array indexes
I have two arrays, each filled with 1000 objects of my own class.
What I want is a recursive loop that will have the corresponding index values of each array interact in a predefined way.

Example:
Array One: 1, 3, 5, 7, 9
Array Two: 2, 4, 6, 8, 10

The way i want them to interact is Array Two minus Array One, then store that in a variable ('1' has a variable for this). Would I do this with a for loop or a while loop, and how would I do it?

EDIT:
Another question:
How would I achieve something like:
If (array[x] == 0)
do something

where x can be any index, and that code is running all the time?

Last edited by Kaito; 10-29-2009 at 03:59 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-29-2009, 08:17 AM
Senior Member
 
Join Date: Aug 2009
Posts: 1,895
Rep Power: 2
r035198x is on a distinguished road
Default
Find a tutorial on arrays and read it.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-29-2009, 08:27 AM
Member
 
Join Date: Oct 2009
Posts: 12
Rep Power: 0
Lizzip is on a distinguished road
Default
Originally Posted by Kaito View Post
EDIT:
Another question:
How would I achieve something like:
If (array[x] == 0)
do something

where x can be any index, and that code is running all the time?

In what way do you mean? As is a do while loop?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-29-2009, 02:28 PM
Member
 
Join Date: Sep 2009
Posts: 22
Rep Power: 0
AlbertoPL is on a distinguished road
Default
A do while loop is a good bet.

Also, you'll probably want to use a for loop if you know the size of the array you're iterating on.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-30-2009, 04:01 AM
Member
 
Join Date: Sep 2009
Posts: 10
Rep Power: 0
Kaito is on a distinguished road
Default
Alright, new problem statement, which should make more sense:
"At index 0, have some code run that will randomly subtract either 2 or 0 from a counter. When the value at index 0 reaches 0, I want the same bit of code to run for index 1, then index 2, etc, until the last index value has been reached"
Does this make it easier to understand?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-30-2009, 04:14 AM
Member
 
Join Date: Sep 2009
Posts: 22
Rep Power: 0
AlbertoPL is on a distinguished road
Default
Yes your new statement makes a lot more sense.

You say you want to go through each index value. You can probably figure out what kind of loop you need to go through each one.

Then, for each of those values, you want to keep going until the value at the index is 0. Again, try to think of what loop you need for that.

Inside that 2nd loop you can do your random subtractions. Try to see if you can do this, it should be a fairly big hint as to how to proceed.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Lucene allows to split a document tokens between several indexes? zakeri@srrf.net Lucene 1 11-04-2009 06:58 PM
Removing Indexes gilbertsavier Database 0 07-17-2009 08:23 AM
Creating Indexes gilbertsavier Database 0 07-17-2009 08:23 AM
How to add an integer to a array element and the store that backinto an array. Hannguoi New To Java 1 03-31-2009 07:40 AM
Auto updation of Editable Column Indexes Gajesh Tripathi AWT / Swing 0 10-23-2008 11:23 AM


All times are GMT +2. The time now is 10:28 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org