java - Trouble with using a simple boolean -
sorry if stupid question, im new , trying hand. code stuck....after point, program ends, no matter whether 1 or 2 selected. know simple im missing....any input appreciated. have copy , pasted section in think problem lies below.
system.out.println("is information correct? enter 1 if correct, , 2 change"); scanner inputcorrect = new scanner(system.in); int pick = inputcorrect.nextint(); boolean iscorrect = false; while (iscorrect = false){ while (!(pick == 1) && (!(pick ==2))) system.out.println("that not valid entry please try again"); if (pick == 1){ iscorrect = true; } if (pick == 2){ system.out.println("enter 1 change name, 2 change age or 3 change gender"); scanner inputchange = new scanner(system.in); int change = inputchange.nextint(); if (change ==1){ scanner inputnewname = new scanner(system.in); system.out.println("enter correct name: "); string correctedname = inputnewname.next(); you.setname(correctedname); system.out.println(you); iscorrect = true; } if (change ==2) { scanner inputnewage = new scanner(system.in); system.out.println("enter correct age: "); int correctedage = inputnewage.nextint(); you.setage(correctedage); system.out.println(you); iscorrect = true; } if (change == 3) { scanner inputnewgender = new scanner (system.in); system.out.println("enter correct gender: "); char correctedgender = inputnewgender.next().charat(0); you.setgender(correctedgender); system.out.println(you); iscorrect = true; } } }
in while loop
while (iscorrect = false){
you using assignment operator, =
, it's false.
you want comparison operator ==
compare if values same.
while (iscorrect == false){
since it's boolean
, may want use iscorrect
itself:
while (!iscorrect)
Comments
Post a Comment