File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Having trouble getting started with an array method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having trouble getting started with an array method" Watch "Having trouble getting started with an array method" New topic
Author

Having trouble getting started with an array method

russell lloyd
Greenhorn

Joined: Feb 09, 2005
Posts: 18
Hello everyone first off let me say that this assignment is for school but I'm not trying to mooch I want to learn. My assignment is to write 8 different methods that do vaious things to arrays. I have done a couple of the methods no problem but on this one I don't even know where to start.

The Idea is that we take in an array of ints and some target value and I'm supposed to print out all the indices of all sets of 3 elements which sum to the target value.

My idea so far is to create for loops that will add the three different indices. My problem is I don't know how to write the for loop to ensure that all of the different combinations of elements will appear.

anyways thanks for any help.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
The brut force method would use 3 nested for loops.
The outer loop thru all but the last 2 items
Tne next in would thru outter index + 1 to next to last
The inner thru the mid index + 1 to last item
Add the contents of the array pointed to by the three indexes and compare it to the desired sum.
russell lloyd
Greenhorn

Joined: Feb 09, 2005
Posts: 18
Okay this is the code that I wrote and It's not working if anyone could take a look at it and point me in the right direction as far as debugging goes that would be great.
russell lloyd
Greenhorn

Joined: Feb 09, 2005
Posts: 18
okay never mind that last post I figured it out i was adding the numbers together instead of the indices of the numbers.

THANKS FOR ALL THE HELP I'M SURE I'LL BE BACK ON THIS ASSIGNMENT!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having trouble getting started with an array method