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"}
11 ответов
+ 4
vlada you are right, I missed that.
// I added version 2
+ 2
Gafoor Ezzati code you marked as best answer doesn't fit in your solution pattern. There is no possibility for repeated values.
+ 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.
+ 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
+ 1
its ok
i solve it
+ 1
Thank you for your code
+ 1
Gafoor Ezzati you're welcome 😊
+ 1
Michal
vlada
Thank you for helping me
0
Thanks for your code
0
thanks