java - Run two while loops one after another taking user input -


in method want user input if passes first while need go second while loop, in second while if condition fails need re-run loop instead of re-running itself, first while being executed.

//method read, validate , store postcode , purchase amount n customers public  void addrecord(int customercounter) throws ioexception {     int postcode;     double purchaseamount;      int conform =0;      do{         bufferedreader breader= new bufferedreader(new inputstreamreader(system.in));         system.out.print("postcode: ");         postcode= integer.parseint(breader.readline());          if(4121 >postcode)         {             system.out.print("postcode must greater 4121");             system.out.print("try again: ");                                     }         else if(postcode > 4123)         {             system.out.print("postcode must less 4123");             system.out.print("try again: ");                                     }         else         {             conform = 1;             //system.out.println(conform);         }     }     while(4121 >postcode && postcode > 4123);        if(conform == 1)     {         system.out.println(conform);                 {             bufferedreader breader2= new bufferedreader(new inputstreamreader(system.in));             breader2= new bufferedreader(new inputstreamreader(system.in));             system.out.println("purchase amount: ");             purchaseamount= double.parsedouble(breader2.readline());              if(purchaseamount < 60)             {                 system.out.print("purchase amount must greater $60");                 system.out.print("try again: ");                 continue;             }             else if(purchaseamount > 500)             {                 system.out.print("purchase amount must greater $500");                 system.out.print("try again: ");                                                             }                    }         while(purchaseamount < 60 && purchaseamount > 500);               }     } 

your conditions in while wrong, false

postcode = 5000; while(postcode < 4121 && postcode > 4123); -> while(false && true); -> false  postcode = 3000; while(postcode < 4121 && postcode > 4123); -> while(true && false); -> false 

use or instead of and

while(postcode < 4121 || postcode > 4123); 

same goes second while.

the second execution of first while because call addrecord again.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -