Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-20-2012, 05:28 PM   PM User | #1
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
1. What is the purpose of while (!validBet) in this code?

Code:
import javax.swing.JOptionPane;

public class BettingQuestion {

public static void main (String [] args) {

int bank = 1000;
int bet;
boolean validBet;

JOptionPane.showMessageDialog(null, "You can bet between 1 and " + bank);	
do {
bet = Integer.parseInt(
JOptionPane.showInputDialog(null, "Enter your bet:"));
validBet = true;
if (bet <= 0 || bet >1000) {
validBet = false;
JOptionPane.showMessageDialog(null, "What, are you crazy?");
}
} while (!validBet);	

JOptionPane.showMessageDialog(null, "Your money's good here.");
}
}
dannyboi is offline   Reply With Quote
Old 08-20-2012, 06:06 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
! evaluates to NOT. So in this example, do/while validBet is false.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
java, java programming

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:58 PM.


Advertisement
Log in to turn off these ads.