+ 1

I need help with my code.

You can get my code here: https://code.sololearn.com/c6dny7SawtnM Basically, im trying to make a code, where by when someone enters a word, the code returns all possible rearrangements of the letters within the word and on top of that, it returns all possible values within the range of the letters. Example: a user types in "oa", the program then rerturns : ao , aa and oo . Just to add, my program is accomplishing all of this but its just executing the code continuously and repeating words, which i dont want to happen. If anyone is reading this, please dont steal my code. I understand how to solve the problem in my head step by step but i cant make it happen in the actual code. I must've been staring at the monitor for too long lol.

26th Nov 2017, 6:17 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
4 Respuestas
+ 3
Since you are using random selection , Put all the new arrangements into an array and everytime the program creates a new arrangement loop through the array and check whether it is already present or not , if present then don't include it in the array . Finally print the array I think there would be better methods of finding all the arrangements than selecting randomly , try to make or find it out :)
26th Nov 2017, 6:01 PM
Utkαrsh
Utkαrsh - avatar
0
I'll research how an arraylist works , thanks. In my code i tried using a do while loop, i was hoping that would solve the problem but it didnt. I tried doing while(!z.equals(z)); but when i did this , it only prints out one permutation of the word. I thought that if i used that code i just stated, the loop will only execute when the random generated value is not equal to the value inserted by the user and the previous permutations but its not working either. Can someone explain why it doesnt work, please ?
26th Nov 2017, 6:27 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
0
But if i use an array, dont i need to established a fixed sized?. If i do need to add a fixed size, then it wont be very helpful as different lengths of words will have different amounts of permutations. Am i making sense?
26th Nov 2017, 6:31 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar