Results 1 to 3 of 3
- 10-23-2009, 09:08 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 8
- Rep Power
- 0
Need help - I can't figure it out.
I'm not sure what to do with the while to make this code work.Java Code:boolean correct = false; do{ numTextBook = Integer.parseInt(JOptionPane.showInputDialog("How many text books are you buying?")); if(numTextBook >= 0 && numTextBook <= 6) correct = true; } while (numTextBook >= 0 && numTextBook <= 6);
Any help would be appreciated!Last edited by Fubarable; 10-23-2009 at 10:11 PM. Reason: Code tags added to aid code readability
- 10-23-2009, 09:22 PM #2
Member
- Join Date
- Oct 2009
- Posts
- 63
- Rep Power
- 0
What do you want it to do? Right now it's going to go through the DO at least once, and if numTextBook is between 0 - 6 it's going to set correct = true. and if it's true it's going to keep going in the loop indefinitely.Java Code:boolean correct = false; do{ numTextBook = Integer.parseInt(JOptionPane.showInputDialog("How many text books are you buying?")); if(numTextBook >= 0 && numTextBook <= 6) correct = true; } while (numTextBook >= 0 && numTextBook <= 6);
-
You've got a boolean variable, correct, why not use it in the while condition? Which would work better do you think,
orJava Code:while (correct); // repeat while correct input given
Java Code:while (!correct); // repeat while correct not yet given
Similar Threads
-
Need Help in BlueJ... Cannot figure this out.
By ERICAMAUVE4 in forum New To JavaReplies: 2Last Post: 09-25-2009, 12:34 AM -
I couldn’t figure out how to do this please help!
By afrttoh in forum New To JavaReplies: 5Last Post: 11-19-2008, 08:21 PM -
Cannot figure out min and max, without using arrays. if possible.
By loddog2002 in forum New To JavaReplies: 2Last Post: 11-08-2008, 04:58 AM -
Please Help, can't figure out what I'm doing wrong.
By tamik0 in forum New To JavaReplies: 2Last Post: 07-11-2008, 09:41 AM -
I can't figure this out
By silvia in forum New To JavaReplies: 3Last Post: 07-20-2007, 04:38 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks