Jump to content

JAVA PROGRAMMING HELP


katalyst

Recommended Posts

Posted

Alright i'm having a little problem at the moment. Long story short i need to switch the numbers in 2 places of arrays. Here's a little sample of something sort of like i want.

for(int i=0;i<10;i++){
array[i]=array[random.nextInt(10)];
}

What that little chunk there does is randomly set the number to another number in that arrays place. I can't figure out how to make the random array slot that is chosen equal to the one that i'm using the loop for.

I hope i'm making sense. Pretty much with what i have there i get multiples of the array slots. Ex.


array[]={10,20,30,40,50,60,70,80,90,100};

I get:
array[0]=10;
array[1]=30;
array[2]=10;
array[3]=50;
array[4]=60;
array[5]=20;
array[6]=10;
array[7]=40;
array[8]=100;
array[9]=70;

I want:
array[0]=20;
array[1]=50;
array[2]=70;
array[3]=80;
array[4]=10;
array[5]=30;
array[6]=60;
array[7]=40;
array[8]=100;
array[9]=90;

see how it doesn't repeat

Well i want that. Anyone want to give me a basic less then 5 line loop that will do that for me?

Posted

over my head. by far.

Posted

idk much java but the parameter for nextInt might be whats causing 10 to repeat

try putting i, or just nothing... if that doesnt work idk what to tell ya

for(int i=0;i<10;i++){
array[i]=array[random.nextInt(10)];
}
Posted

I'm sorry but i don't know what to do in that situation, but i bet that this topic is getting spammed by +1'ers soon.

Posted

I don't know.

Big Jim is always glad to be of assistance.

Posted

I don't know.

Big Jim is always glad to be of assistance.

: ) well next time idk what's going on I think i'll have to ask you. Java can be such a pain in the ass sometimes. Python is nicee and easy. Just make a set and fill it. Can't duplicate a number in a set so your gravy.

Posted

Go oldschool and program in C.  Shit's so cash.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.