ô§§|E
Supreme tranceaddict
Registered: Apr 2004
Location: Perth, Australia
|
|
|
Firstly, where's your default constructor for the PositionPair Class? cause at the moment you cant even create one of these objects right? So make one of those.
code:
public PostionPair()
{
firstOccurence = -1;
secondOccurence = -1;
}
Ur missing one lil concept here i think, the line ....
code:
PositionPair[] positions = new PositionPair[10];
Doesn't magically give you instantiations of 10 PositionPair objects, you still need to do this via ...
code:
for(int a = 0; a < 10; a++)
{
positions[a] = new PositionPair(); //You'll need a default constructor for this!
}
so now ur code looks like ....
code:
int[] digitArray = { 0, 1, 1, 3, 4, 5, 5, 7, 8, 9 };
PositionPair[] positions = new PositionPair[10];
//ADDED CODE
for(int a = 0; a < 10; a++)
{
positions[a] = new PositionPair(); //You'll need a default constructor for this!
}
for (int i = 0; i < digitArray.length; i++)
{
for (int z = i + 1; z < digitArray.length; z++)
{
if (digitArray[z] == digitArray[i])
{
positions[i].setFirstOccurence(i);
positions[i].setSecondOccurence(z);
System.out.println(i);
System.out.println(z);
}
}
}
Should do the trick by initialising the objects in the array first, let me know how that works for you
___________________
| quote: | Originally posted by eye_03
the reason why i dont do it is because i see people like you at clubs doped out of your mind. i say "shit, i dont wanna turn out like that scumbag" |
Last edited by ô§§|E on Oct-15-2006 at 12:17
|
|