getting duplicate array output - java -


Can anyone be kind and can help me in advance thanks ...

given below Output the code string as a duplicate. I do not want to use set or arraylists I am using java.util.Random I am trying to write a code that checks that if the string has already been randomly outputed and if this happens, Then it will not be displayed. Where am I going wrong and how can I fix it.

  Public Square Encyclopedia {Private Stable Random nums = new random (); Private static string [] Countries = {"America", "Candda", "Chile", "Argentina"}; Public stable in dies () {returns (generator.nom.Nutant (6) + 1); } Public string random number () {string aTemp = ""; Int numOfTimes = Dice (); Int dup = 0; For (INTI = 0; I  

So I think that "America, Chile" should be when "America, America and Chile", getting output (randomly) I

You might be better off using another framework, where you save the printed wires. Since you do not want to use a set, you can use an array instead of something like this

  / * ... * / bool [] printed = new bool [Countries.length]; For (int i = 0; i & lt; numOfTimes; / * noop * /) {int r = nums.nextInt (countries.length); If (printed [r] == wrong) {i = i + 1; Printed [r] = true; ATemp = aTemp + Country [R]; ATemp = aTemp + ","; }} ATemp;  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -