Results 21 to 40 of 136
Thread: Help with arrays
 03062012, 11:09 PM #21Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
 03062012, 11:17 PM #22
Re: Help with arrays
To work with the individual digits in the number you could split the digits out into a 6 element array. If the number is already in a 6 element array, then you won't have to do that step.
To see what I'm saying about taking 5 of the 6, write down a 6 digit number on a line, then on the lines underneath that number write all of the numbers that use 5 of the 6 digits. The process you use to generate each of those lines would be what you would code in your program.
 03062012, 11:22 PM #23Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
But I don't even know what I am checking for!
It wouldn't be searching through the array thats the problem, its getting it to do what I want... i.e. find the smallest number to pull out
 03062012, 11:25 PM #24
Re: Help with arrays
Finding the smallest digit in the array would be very easy to do in a loop
 03062012, 11:30 PM #25Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
But taking out the smallest digit doesn't necessarily make the new number divisible by 3
 03062012, 11:31 PM #26
Re: Help with arrays
That's why there is a loop. The numbers are sorted high to lowest.
 03062012, 11:36 PM #27Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
But now what if you need to take out 2 numbers in order for the new number to be divisible by 3? if statement and a new loop?
 03062012, 11:45 PM #28
Re: Help with arrays
Do it one thing at a time. Worry about removing 2 digits after you get it working for 1 digit.
 03062012, 11:57 PM #29Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
Well actually, how can I do that? How do I remove one of the digits from the array and then add up all of the digits less that one that we are checking?
 03072012, 12:00 AM #30
Re: Help with arrays
You can leave it in the array and just not use it. The loop index points to the digit not to be used when adding up.
 03072012, 12:04 AM #31Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
So then how do I go about adding up the others? do I have to add another index or something?
 03072012, 12:07 AM #32
Re: Help with arrays
Make a small simple program to add together the contents of an int array with 3 elements using a loop.
When that works, add logic that only adds two of the three elements.
 03072012, 12:10 AM #33Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
What about using a recursive loop? would that be more effective?
 03072012, 12:11 AM #34
Re: Help with arrays
Try it and see what happens.
Loops are not recursive, methods are.
 03072012, 12:43 AM #35Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
I'm honestly at a loss... I am thinking right now set up 5 index's and just going from there
 03072012, 12:45 AM #36Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
What about a linked list?
 03072012, 12:55 AM #37
Re: Help with arrays
Can you do this:
Make a small simple program to add together the contents of an int array with 3 elements using a loop.
 03072012, 01:13 AM #38Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
yes
Java Code:int sum; for(int i = 0; i<x.length; i++) { sum += x[i] }
 03072012, 01:24 AM #39
Re: Help with arrays
Now add another outer loop that iterates over the size of the array and in the inner loop skip adding x[i] if the index of the outer loop == i
Your test code needs to define a real array with contents and print out the value of sum when the inner loop completes.
 03072012, 01:30 AM #40Senior Member
 Join Date
 Mar 2011
 Posts
 171
 Rep Power
 0
Re: Help with arrays
The problem isn't the loop itself... the problem is what goes inside the loop. I don't know how to add up the array and skip over that one element.
Also I need to do something that will output the new number as a 5 digit number and not just as a sum, but I figure that will be easy once I figure this out... Could you by any chance show me some sample code to work off of?
Similar Threads

Casting Enum Type arrays to object type arrays
By nmvictor in forum Advanced JavaReplies: 4Last Post: 02172012, 01:49 PM 
arrays and multidimensional arrays
By belfast09 in forum New To JavaReplies: 5Last Post: 06142011, 01:28 PM 
help with arrays
By droidus in forum New To JavaReplies: 20Last Post: 04192011, 06:29 AM 
store array of arrays in array of arrays
By joost_m in forum New To JavaReplies: 4Last Post: 04192010, 10:32 AM 
Arrays.sort... why sorting all arrays in class?
By innspiron in forum New To JavaReplies: 6Last Post: 03232010, 02:40 AM
Bookmarks