Why my program does not loop back during invalid input?

          boolean invalidNum = false;           
                  //Questionnaire Number
                    do {
                    System.out.print("Enter Questionnaire Number [ ] ");
                      try
                           inputQuestionnAireNum = Integer.parseInt(input.nextLine());
                           if(inputQuestionnAireNum <0 || inputQuestionnAireNum>100){
                                System.out.print("Invalid: please enter between 1 to 100 \n");
                           } else {
                                invalidNum = true;
                      catch (NumberFormatException e)
                        System.out.print("Invalid try again \n");
                    } while (!invalidNum);
                    //Age input
                    do {
                         System.out.print("Enter Age [ ] ");
                           try
                                inputQuestionnAireNum = Integer.parseInt(input.nextLine());
                                if(inputAge <0 || inputAge>100){
                                     System.out.print("Invalid: please enter between 1 to 100 \n");
                                } else {
                                     invalidNum = true;
                           catch (NumberFormatException e)
                             System.out.print("Invalid try again \n");
                         } while (!invalidNum);
                    //Postal code
                    System.out.print("Enter Postal Code [ ] ");     
                    inputPostCode = Integer.parseInt(input.nextLine());Result:
1 new entry or 0 print1
Enter Questionnaire Number [ ] w
Invalid try again
Enter Questionnaire Number [ ] 33
Enter Age [ ] w
Invalid try again
Enter Postal Code [ ]
why age input does not loop back and prompt for re-enter during invalid input ? instead it proceed to print the next line.

Apparently because you don't reset "invalidNum" after the first loop.
Your code would be a lot easier to read if you didn't use the word "invalid" to mean "valid".

Similar Messages

  • Why my program does not run on?

    I am writing a java project, a little big, to analyze a forum. The tasks I have to complete are:
    *(1) Register all threads (the post begins a new thread just like this post) existed in the forum during a period of time (for example 2 weeks) in the database.*
    *(2) After recorded every thread, crawl each thread to record the information of all the posts after (belong to) it (including the beginning post). These information include post author, posting time and post content. The author and time information will be stored in database and all the post content of a thread will be written into a unique .txt file, which means for each thread there will be a .txt file to record all the text posted to it.*
    The (1) is completed as I crawled the thread list pages of the forum for 2 weeks. And then write a text parser to extract all the thread item information into database. Now I have a table in the database which records all the threads that existed in the forum in the past 2 weeks. I can read thread url, posting time, thread author, thread title and thread id from the table.
    Then I plan to do the second job. I write a project in this way
    Begin
    HashMap threadUrl_threadID(10000), threadUrl_threadTitle(10000)
    ArrayList authorList(150000), threadAnalyzedUrlList(10000);
    Read from database to initialize the above instances
         Iterator iterator=threadUrl_threadID.keySet().iterator();
         while(iterator.hasNext)
              threadUrl=iterator.next();
              if(!threadAnalyzedUrlList.contains(threadHplink))
                   StringBuffer wpBuffer=webPage2Buffer(threadUrl);
                   // The Parser analyze the webpage and extract the information needed and has not been recorded
                   Parser.analyze(wpBuffer) and write to database
                   // If a thread has many posts, it may spread to many pages. Also crawl those pages.
                   while(nextPageExisted)
                        Read and parse next page.
                   Write all the post content to a local .txt file
                   update all ArrayList instances such as authorList and so on.
    EndI try to avoid recording duplicate information and querying database too often.
    Thus at the beginning of the program, I read all the items I will need from the database.
    And then update them to avoid query database. I think it's efficient but not too sure.
    This project works not bad when the volume of the threads (thread means the first post
    that opens a topic) is around 1000. But after I run the project on the practical database which
    stores almost 10000 threads. At the beginning it runs well, but always after 30 minutes the program
    seems suspended on its own. No exception is thrown out. In the console window of eclipse, it shows the program
    is still running (after 30 minutes). But no .txt file which stores thread content is produced
    and no new items are added into the database. Windows taskManager shows the cpu is used at a very low rate.
    I can't figure out what is wrong. I doubt maybe those ArrayList instances grow too large to
    exceed some tolerated limits.
    Can anyone offer some suggestions?
    See you tomorrow~

    Thanks paul. I let the program run all night last night. Actually nothing is wrong. The problem is some threads are so long that it needs almost 1 HOUR to complete it and generate the .txt file. I write no output info during this process. Thus sometimes it looks suspended but in fact the program is still running.
    Thank your reply very much!

  • Why the mouse pointer in Logic Pro does not change shape during work in OSX 10.9.1?

    I've a MacBook Pro Retina 15-inch Late 2013 and I'm using two external displays. One connected to to the HDMI port (display 1) the other to thunderbolt (display 2). The MacBook display is closed. I’m working with Logic Pro 9.1.8 (32bit) with OSX 10.9.1
    Why the mouse pointer in Logic Pro does not change shape during work???
    It was already difficult with OSX 10.9 but now after upgrading to 10.9.1 it's game over!
    At least before I could select which display use Logic Pro to have all the shape functions of the pointer. Not in both displays, so to be forced to edit in ONLY ONE of the two displays using this workaround: (right click on Logic icon in Dock: Option --> Desktop on Display 1). Now or I select “Option --> All Desktops” or does not work. However, by selecting all displays you say goodbye to Mission Control. This can’t be a solution!!!
    The amazing thing is that Nuendo has no problem while Logic Pro, Apple's native software, it can't!
    With Nuendo it’s indifferent in which display you are working, the shape of the mouse pointer changes shape depending on the requirement in both displays.
    This thing drives me crazy!
    Solutions?
    Here some ideas in other foums:
    http://www.logicprohelp.com/forum/viewtopic.php?f=1&t=86264
    But this aren't really solutions but workarounds. Use Logic in all desktops makes Mission Control useless!!

    I installed all over again by formatting as suggested by the genes of pro application support. Each plug-in, each virtual instrument, a job that lasted 3 days. And as suggested for each new plug-in I proceeded to check the proper functioning of Logic Pro and did each time a back up with Time Machine.
    The Result:
    Logic works as it should ONLY on the primary monitor and ONLY on the first desktop.
    BUT
    Reason and Nuendo dont' have this issue !!
    I believe that Apple developers are thinking only to mobile phones and things like messages or face time.
    And that's not all!
    After a few weeks, perhaps by installing a version of Adobe Acrobat, I say maybe because I'm not sure, logic has stopped working properly. Again problems with the mouse pointer.
    Luckily I had a back up! But now I'm terrified to install new programs. Thanks Apple!

  • TS3694 Hi, My iphone 5 loses the 3G connections everytime i go into tunnel and also to holland park and it does not come back untill i restart the phone? i dont know why is it happening?

    Hi, My iphone 5 loses the 3G connections everytime i go into tunnel and also to holland park and it does not come back untill i restart the phone? i dont know why is it happening?

    Hi, beth.lau.gr.
    Thank you for visiting Apple Support Communities.  
    I understand you have been experiencing issues with your iPhone restarting and showing you a blue screen.  I wont be able to give you an exact answer as to why this is happening.  However, this is the most relevant troubleshooting article for this issue.  This article also provides options to reach out to us via phone for additional assistance.  
    If your iOS device restarts, displays the Apple logo, or powers off while you're using it
    http://support.apple.com/en-us/HT203899
    Cheers, 
    Jason H.  

  • HT4367 Whenever I try to rent a movie, Apple TV buffers and does not come back.  I am able to see other programs, but not able to rent movies.   And the movie charge still goes on my bill.

    Whenever I try to rent a movie, Apple TV buffers and does not come back.  I am able to see other programs, but not able to rent movies.   And the movie charge still goes on my bill.

    Apple TV uses iTunes. The reason you can't rent through your ATV is because you can't rent movies through iTunes Canada. Sadly, as this is a user-to-user forum, no one here would know when or if rentals will come to Canada.

  • Why a bdc program does not run background

    <b>why a bdc program does not run background</b>
    Thanks.

    HI,
    BDC programs can run in the background, If you use the Functionmodules which is Uplpoad a file from Presentation server or Upload from presentation server then we can not use the Program in the Background processing. if the BDC program does not have these function modules then we can use the program in Background
    Regards
    Sudheer

  • My CS5 program does not support CR2 photo taken with Canon Rebel T5i. Why?

    My CS5 program does not support CR2 photo taken with Canon Rebel T5i camera.  Why?

    If you take a look at the following charts, you will find that both the S110 and the T5i are not supported in CS5, both cameras require photoshop CS6 with a camera raw point upgrade, Photoshop CC or Lightroom 4.3(s110) 4.4(T5).
    Camera Raw plug-in Supported cameras
    http://helpx.adobe.com/creative-suite/kb/camera-raw-plug-supported-cameras.html
    Photoshop CC indepth : camera raw - Supported cameras for plugin and lightroom
    http://www.adobe.com/products/photoshop/extend.html
    Camera Raw-compatable Adobe applications
    http://helpx.adobe.com/x-productkb/global/camera-raw-compatible-applications.html

  • Why is my downloaded Lightroom CC (2015) does not start? The download is successful otherwise okay. The shortcut appears on the desktop etc. But the program does not start.

    Why is my downloaded Lightroom CC (2015) does not start? The download is successful otherwise okay. The shortcut appears on the desktop etc. But the program does not start.

    Thank you help ! [?]
    2015-04-29 19:58 GMT+02:00 kglad <[email protected]>:
        Why is my downloaded Lightroom CC (2015) does not start? The download
    is successful otherwise okay. The shortcut appears on the desktop etc. But
    the program does not start.  created by kglad
    <https://forums.adobe.com/people/kglad> in *Creative Cloud Download &
    Install* - View the full discussion
    <https://forums.adobe.com/message/7495290#7495290>

  • Button does not pop back.

    Hi,
    I trigger  a dialog on mouse down event on one button which is located on my GUI. But  after the user finished the dialog the button that invoked the dialog does not pop back. Is the button supposed to pop back automatically or am I supposed to programatically pop it back?
    Thanks.

    RSibagatullin wrote:
    Hmm,
    I just checked the button and it says  "Latch when pressed". Will changing event to "Value change" help me?
    No, this will not help. In order for a latch action boolean to revert, it needs to be read by the code, i.e. be in the dataflow. If the terminal of the boolean is somewhere random on the diagram there is no garantee that it will get read after a press (e.g. If the terminal is outside the main while loop, it will be in the dataflow exactly once at the start of the program and then never again).
    Why don't you attach a simplified version of your program so we can see where the problem is. 
    LabVIEW Champion . Do more with less code and in less time .

  • Why are animated gifs not looping

    I can not understand why an animated gif set to loop twice does not loop at all. same file works in all other browsers.

    This page explains the settings for that:
    * http://kb.mozillazine.org/Firefox_:_Tips_:_Animated_Images

  • Mercedes User interface does not revert back after a call

    I had my iPhone 4 paired to my Mercedes and was happily using the bluetooth connectivity for making and receiving calls .
    But lately when I make a call by dialing from my phone and then disconnecting the call using the car control, the car screen does not revert back to what it was and it remains in the phone mode.
    This does not happen when I pick up a call using the car control.
    Any idea as to why this might be happening .

    Uninstall then reinstall RNR.  RNR does not like to be cancelled via task manager.... this creates a mess.
    Reinstall may also fix your issue with productivity center.. 

  • Why apple tv does not sell in hong kong?

    Why apple tv does not sell in hong kong?

    appletv's only sell in countries where itunes have rights to sell movies and tvshows
    so if your kong kong itunes store dont sell such data they don't sell the appletv
    likely because they sell them at a price where they lose money but depend on rental and buying of media
    to earn back those lost money but they can only do that if they have rights to sell and rent media in the place

  • Why apple tv does not show in itune?

    why apple tv does not show in itune?

    Welcome to the Apple Community.
    I assume you have the Apple TV 1.
    Often a restart of ALL your equipment will help, it may also be a result of instaling or updating security software (check your security settings).
    If problems persist, navigate to Settings > Computers > Your Library on the Apple TV, you may be told you will lose all synced content, but you can sync it back afterwards, you won't lose any purchased content that has yet to be transferred. Then select Settings > Computers > Connect To iTunes, note the passcode that appears on screen, click on the device in iTunes and enter the passcode when prompted.

  • I can not create an Installer, After install the Vision Builder Demo and then uninstall it. I can not create a Labview installer anymore, it asks me for a Vision Builder Installer, even if My Labview program does not have nothing to do with it...

    I can not create an Installer on LabView, After install the Vision Builder Demo and then uninstall it. I can not create a Labview installer anymore, it asks me for a Vision Builder Installer, even if My Labview program does not have nothing to do with it...
    Solved!
    Go to Solution.

     Hi Shada this can happen if you are including additional installers to your installer for example DAQmx. When you are doing this the installer has to include other files like MAX (Measuremente and Automation Explorer). Probably when you installed Vision Builder it updated MAX, so when your installer is trying to Include MAX, its asking for the source where it was installed in your computer in this case Vision Builder.
     Here you can cache the information so its not asked again, or you can download a newer version fo DAQmx, so it will update MAX and change de dependecy.
     You can find more details about this issue in this KB:
    KnowledgeBase 3S88PJMY: Why Do I Get A "Missing Distribution" Error When Trying to Build an Installe...
    And for keeping a copy here is more info:
     How Do I Stop the Missing Distribution Notification Each Time I Build An Installer?
    Best Regards
    Benjamin C
    Senior Systems Engineer // CLA // CLED // CTD

  • Why the itunes does not take my ipod 4g

    why the itunes does not take my ipod 4g

    this worked for me, below.
    from:
    http://docs.info.apple.com/article.html?artnum=93716
    Reinstall the COM interface for the iPod Service
    1. Quit iTunes and any running iPod Updater.
    2. Click iPodService.exe in the Windows Task Manager window.
    3. Click End Process.
    4. Click Yes.
    5. On the Start menu, click Run. Note that the Run windows may appear behind the Windows Task Manager window.
    6. Enter this text (including the quotation marks):
    "C:\Program Files\iPod\bin\iPodService.exe" /service
    7. Click OK in that window.
    8. On the Start menu, click Turn Off Computer.
    9. Click Restart.
    If the iPod is not working with iTunes or the iPod Updater, proceed to the "Quick Fix" section below.

Maybe you are looking for