Results 1 to 3 of 3
  1. #1
    Romally is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default do while (variable != type)

    Having a problem here. I wanted to make the segment of code repeat until a basic condition was met, type. As you can see below, I try just that, however, it won't let me create a condition based on type. Why? How do I get around this? I checked a couple resources on this and all I could find were examples based on a basic counter system.

    Here's the code:

    Java Code:
    do
    		{
    			String settingAccountNumber =
    			JOptionPane.showInputDialog( null, "Please enter your account number: "); // Get input
    		int i = Integer.parseInt( settingAccountNumber  ); // Translate string to "int"
    		} while ( i != int);

    Basically, I'm trying to follow along with a project inside the book by creating a basic functioning ATM machine. The section that talks about while and do while doesn't say anything about basing them off type. I assumed either it was an advanced lesson or it didn't exist.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You would probably use a try/catch block here and catch the NumberFormatException for this to work well. Lots of examples of this on this forum and elsewhere.

  3. #3
    Romally is offline Member
    Join Date
    Nov 2010
    Posts
    12
    Rep Power
    0

    Default

    Hey thanks for pointing me where I needed, found official docs to look at. Cheers!

Similar Threads

  1. Replies: 11
    Last Post: 07-07-2010, 06:02 AM
  2. Replies: 1
    Last Post: 12-09-2009, 12:57 AM
  3. using instanceof to get Object type and parent type?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-06-2008, 06:24 PM
  4. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 10:43 AM
  5. [SOLVED] curiosity about String type variable
    By monir6464 in forum Advanced Java
    Replies: 1
    Last Post: 04-08-2008, 11:13 AM

Posting Permissions

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