using a do while loop to search array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: using a do while loop to search array

Threaded View

  1. #1
    Join Date
    Jul 2005
    Posts
    32

    Question using a do while loop to search array

    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
    Last edited by JavaSado; 08-02-2005 at 08:45 AM.

Similar Threads

  1. Replies: 2
    Last Post: 04-15-2005, 09:06 PM
  2. Loop Reading To Array?
    By Phil O Reilly in forum Java
    Replies: 4
    Last Post: 03-12-2005, 12:57 PM
  3. What's up with the Devx search engine???
    By Larry Serflaten in forum Talk to the Editors
    Replies: 3
    Last Post: 02-04-2002, 10:54 AM
  4. HOW CAN I CREATE ARRAY IN SQL 6.5
    By Toms Ng in forum Database
    Replies: 1
    Last Post: 12-18-2001, 09:08 AM
  5. Beef up that search engine!
    By Larry Serflaten in forum Talk to the Editors
    Replies: 3
    Last Post: 07-16-2001, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center