Hi
I have got an array to generate random numbers and am now trying to introduce a boolean expression so that when the numbers are being generating, if a number is found to be in the array already another number is generated.
I cannot compile the code below, as it says the for the } just after the while line "Syntx error, insert "while(Expression);" to complete DoStatement"
Can anyone point me in the right direction with what I have done wrong?
Does my code look like it will do what i want it to?
Any help greatly appreciated - thank you![]()
My code is:
Code:public class BinaryTreeAction { public TreeNode tn; // graphical representation of the node public TreeNode torch; // torch pointer to node public int NodeSize = 25; int amount = 6; // number of integers needed to generate int[] nums = new int[amount]; int i; // method for searching the array for duplicate numbers boolean fresh (int [] nums, int val){ for (int i = 0; i < amount; i++){ if (nums[i] == val) return true; } { return false; } }// end fresh method //method to generate random numbers to insert into the tree public void randomNumber(){ for (int i=0; i<amount; i++){ do{ nums[i] = (int) Math.floor(Math.random() * 100); // generate numbers between 0 and 99 nums[i] = nums[i] -50; // minus 50 from the random number generated so that some of the final numbers are negative. for (int i = 0; i<nums.length; i++){ System.out.println("random is " + nums[i]); } while (not(fresh(nums,i))); } }// end of randomNumber method


Reply With Quote


Bookmarks