Results 1 to 6 of 6
Thread: Loop probrem
- 06-17-2009, 12:16 PM #1
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:
- 06-17-2009, 06:41 PM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
i and t need to change for this to stop loopingJava Code:while (i < t){ ResultTable.setValueAt(delta, i,0); ResultTable.setValueAt(power, i, 1); }
- 06-19-2009, 12:45 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That means the while loop never end, never evaluate to false. That's what emceenugget mentioned.
- 06-24-2009, 04:48 AM #4
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Think it...while (i < t){
i++; //to make the loop finished )))
ResultTable.setValueAt(delta, i,0);
ResultTable.setValueAt(power, i, 1);
}
- 06-25-2009, 04:50 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's all depends on the logic you in the application. :)
- 06-25-2009, 06:03 AM #6
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
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
-
While loop
By verbazon in forum New To JavaReplies: 5Last Post: 02-25-2009, 01:29 AM -
Need help with a loop
By ReV13 in forum New To JavaReplies: 15Last Post: 12-01-2008, 04:48 PM -
While loop
By sjhentges in forum New To JavaReplies: 11Last Post: 11-04-2008, 04:26 PM -
How to use Do While loop
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:45 PM -
How to use While loop
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks