0

(Please help me) random string in java

I need a code in which there is an array of string type. This array is copied to another array to the following two conditions: 1. The first cell of the array does not change 2. Other cells of the array are copied randomly for example: fist arr= {"abc","def","ghi","jkl"} Second arr = {"abc","jkl,"def","def"}

12th Jan 2019, 6:42 PM
Gafoor Ezzati
Gafoor Ezzati - avatar
11 Respostas
+ 4
vlada you are right, I missed that. // I added version 2
13th Jan 2019, 10:31 AM
Michal
Michal - avatar
+ 2
Gafoor Ezzati code you marked as best answer doesn't fit in your solution pattern. There is no possibility for repeated values.
13th Jan 2019, 10:00 AM
vlada
+ 1
Create your 2 arrays, an empty one and the one with the strings in order, use a loop and in the loop make a random number, check if array[rndnum] is null, if so store it into the array eg: second[rndnum] = first[x] if it's not true, you want to do x -= 1 so that all indexes can be filled in since it's random. Here's an example I have made in java, if you got any more questions, feel free to ask. https://onlinegdb.com/rJZyhpvGE Hope it helps.
12th Jan 2019, 8:24 PM
Joery De Loose
Joery De Loose - avatar
+ 1
You could just start the loop at 1 instead and assign the first cell manually second[0] = first[0]; for(int x = 1; x < second.length; x++) { //the random code from my example here } the new code: https://onlinegdb.com/SJkjmRPG4 hope this helps
12th Jan 2019, 8:48 PM
Joery De Loose
Joery De Loose - avatar
+ 1
its ok i solve it
12th Jan 2019, 8:58 PM
Gafoor Ezzati
Gafoor Ezzati - avatar
+ 1
Thank you for your code
13th Jan 2019, 4:30 AM
Gafoor Ezzati
Gafoor Ezzati - avatar
+ 1
Gafoor Ezzati you're welcome 😊
13th Jan 2019, 8:14 AM
Michal
Michal - avatar
+ 1
Michal vlada Thank you for helping me
13th Jan 2019, 11:53 AM
Gafoor Ezzati
Gafoor Ezzati - avatar
0
Thanks for your code
12th Jan 2019, 8:34 PM
Gafoor Ezzati
Gafoor Ezzati - avatar
0
thanks
13th Jan 2019, 8:15 AM
Gafoor Ezzati
Gafoor Ezzati - avatar