Results 1 to 6 of 6

Thread: Loop probrem

  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post Loop probrem

    I am trying to sort a table and i have used several loops for the sorting. Now my program doesnt terminate.
    Could it be something to do with the loop and if so where am i making a mistake coz i just cant figure it out at the moment.
    Also is there a better way to sort the table?
    below is my code

    Java Code:
    public void sortTable(){
        int rCount = InputTable.getRowCount();
        
     for ( int i = 0;i<rCount;i++){
         double delta =0;
        String time =(String) InputTable.getValueAt(i, 0);
        double time1 = Double.parseDouble(time);
    
        String power =(String) InputTable.getValueAt(i, 1);
    
        double t = (time1*60)/5;
            while (i < t){
    
                ResultTable.setValueAt(delta, i,0);
                ResultTable.setValueAt(power, i, 1);
    
            }
        delta = delta +5;
    }
    }
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    Java Code:
            while (i < t){
    
                ResultTable.setValueAt(delta, i,0);
                ResultTable.setValueAt(power, i, 1);
    
            }
    i and t need to change for this to stop looping

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    That means the while loop never end, never evaluate to false. That's what emceenugget mentioned.

  4. #4
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    while (i < t){
    i++; //to make the loop finished )))
    ResultTable.setValueAt(delta, i,0);
    ResultTable.setValueAt(power, i, 1);
    Think it...
    }

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default

    Without sitting down and actually working it out on paper, I can't tell what you are doing, although I am guessing that you actually mean that you are transposing the table or reordering in someway.

    Any kind of sorting algorithm has to have comparisons. Your routine has absolutely none, as of yet. Is the routine part of a larger sorting routine, such as quicksort?

    Webuser is right. You didn't increment i. But computers are very good at boring tasks.

Similar Threads

  1. While loop
    By verbazon in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 01:29 AM
  2. Need help with a loop
    By ReV13 in forum New To Java
    Replies: 15
    Last Post: 12-01-2008, 04:48 PM
  3. While loop
    By sjhentges in forum New To Java
    Replies: 11
    Last Post: 11-04-2008, 04:26 PM
  4. How to use Do While loop
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:45 PM
  5. How to use While loop
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •