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, 12:47 AM   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
Problems with my do-while loop?

Code:
import javax.swing.JOptionPane;
public class Main {

public static void main (String [] args) { 

int bank = 1000;
int bet; 

JOptionPane.showMessageDialog(null, "You can bet between 1 and " + bank);

do
{
   bet =  Integer.parseInt(JOptionPane.showInputDialog(null, "Enter your bet:"));
    
} while  (bet <= 0)|| (bet > bank);
    JOptionPane.showMessageDialog(null, "Your money's good here");
}
}
Also, what does a Scanner class have anything to do with it?
dannyboi is offline   Reply With Quote
Old 08-20-2012, 04:44 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 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
Your condition is invalid. Fix the brackets around them.
Scanner has nothing to do here, but that doesn't matter since there is no reference to the Scanner in this code.
If you're using the ATOI from the integer.parseint, you should be using a try/catch on it.
Fou-Lu is offline   Reply With Quote
Old 08-20-2012, 08:38 AM   PM User | #3
sh4rd
New Coder

 
Join Date: Aug 2012
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
sh4rd is an unknown quantity at this point
Code:
while  (bet <= 0)|| (bet > bank);
to

Code:
while  (bet <= 0 || bet > bank);
sh4rd 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 07:38 AM.


Advertisement
Log in to turn off these ads.