Array

Reply

Join Date: Jan 2009
Posts: 6
Reputation: mona515 is an unknown quantity at this point 
Solved Threads: 0
mona515's Avatar
mona515 mona515 is offline Offline
Newbie Poster

Array

 
0
  #1
Feb 18th, 2009
I've been tryin to figure out how to pick numbers from the 'choices array' and put then into the results array. Can any body help me. I was thinking of adding a for loop but not sure. The code i got so far is below.


import java.util.Random;
import java.util.ArrayList;

public class PermutationGenerator
{
public PermutationGenerator(int length)
{
generator = new Random();
this.length = length;
}

public int[] nextPermutation()
{
int[] result = new int[length];
ArrayList<Integer> choices = new ArrayList<Integer>();

for (int i = 0; i < length; i++)
{
choices.add(i + 1);
}

return result;
}

private Random generator;
private int length;
}
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 807
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 100
stultuske's Avatar
stultuske stultuske is offline Offline
Practically a Posting Shark

Re: Array

 
0
  #2
Feb 18th, 2009
and what are the errors you are getting?
what is it that you don't understand? getting a random element, or storing it in the new array?

I just briefly glanced at your code, and I'm not entirely sure, but trying to store an Integer in an int array .. does seem like a compilation error in the making to me
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 934
Reputation: verruckt24 is just really nice verruckt24 is just really nice verruckt24 is just really nice verruckt24 is just really nice verruckt24 is just really nice 
Solved Threads: 82
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Posting Shark

Re: Array

 
0
  #3
Feb 18th, 2009
I am unclear of what you are trying to do here, so correct me if I haven't understood but instead of copying choices to result and then returning back result, why not return choices.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,191
Reputation: stephen84s is a name known to all stephen84s is a name known to all stephen84s is a name known to all stephen84s is a name known to all stephen84s is a name known to all stephen84s is a name known to all 
Solved Threads: 127
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Array

 
0
  #4
Feb 18th, 2009
Also I would like to suggest to please put your code inside [code=java] and [/code] tags
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2,226
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 273
BestJewSinceJC BestJewSinceJC is offline Offline
Nearly a Posting Maven

Re: Array

 
0
  #5
Feb 18th, 2009
For one, you don't have a main method (that you showed), so you never constructed a PermutationGenerator object and int[] result = new int[length]; has no effect since it is never called.

Secondly, if you wanted to put the stuff from the result array into the choices ArrayList, it would look like (pseudocode)

for each element in result
add the element from result to the choices arraylist
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 76
Reputation: notuserfriendly is an unknown quantity at this point 
Solved Threads: 5
notuserfriendly notuserfriendly is offline Offline
Junior Poster in Training

Re: Array

 
0
  #6
Feb 18th, 2009
well do you just want to transfer all the numbers? or just implement a search method that finds your number and them if it is found it places it into the other array?
please be more clear.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 397 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC