java - System.out.println() and BufferedReader mixing up output in console -
i working on program, uses bufferedreader
read input, , system.out.println()
output.
here code:
public void choosemethod() throws ioexception{ int in = 0; while(true){ system.out.println("what want do? (0 exit, 1 read bank account, 2 write bank account, 3 read bill, 4 write bill): "); in = integer.parseint(cin.readline()); if(in == 0){ break; }else if((in < 0) || (in > 4)){ system.out.println("invalid choice."); }else if(in == 1){ showbankaccount(); }else if(in == 2){ insertbankaccount(); }else if(in == 3){ showbill(); }else if(in == 4){ insertbill(); } } dbm.close(); } public void insertbankaccount() throws ioexception{ int banknr = 0; int sortcode = 0; int accountnumber = 0; int balance = 0; int interest = 0; string details; string name; while(true){ system.out.println("enter banknr (0 exit): "); banknr = integer.parseint(cin.readline()); if(banknr == 0){ break; }else if(banknr <= maxbanknr){ system.out.println("invalid number: taken"); break; } system.out.println("enter account name: "); name = cin.readline(); system.out.println("enter sort code: "); sortcode = integer.parseint(cin.readline()); system.out.println("enter account number: "); accountnumber = integer.parseint(cin.readline()); system.out.println("enter balance: "); balance = integer.parseint(cin.readline()); system.out.println("enter interest: "); interest = integer.parseint(cin.readline()); system.out.println("enter details: "); details = cin.readline(); bankaccountdao.insertbankaccount(banknr, sortcode, accountnumber, balance, interest, details, name); this.maxbanknr = bankaccountdao.getmaxbanknr(); } }
now, enter "2" "write bank account," output follows:
run:
what want do? (0 exit, 1 read bank account, 2 write bank account, 3 read bill, 4 write bill): enter banknr (0 exit): 2
this "2" in output should before "enter banknr(0 exit):"
i have had problem several times, both scanner
, bufferedreader
, , have spent long time googling, can't seem find answers.
has else had problem? if so, how did manage fix it?
in insertbankaccount()
method inside while loop change :
system.out.println("enter banknr (0 exit): "); banknr = integer.parseint(cin.readline());
to:
banknr = integer.parseint(cin.readline()); system.out.println("enter banknr (0 exit): ");
Comments
Post a Comment