java - While loops and string comparisons for my password program -
i trying while loop prints welcome statement if password correct , denies if you're wrong. when you're wrong, want re-ask question. unfortunately, when password wrong, spams end , doesn't reloop. thanks!
import java.util.scanner; public class review { public static void main(string[] args) { scanner userinput = new scanner(system. in ); system.out.println("enter user password"); string userguess = userinput.nextline(); int x = 10; while (x == 10) { if (userguess.equals("test")) { system.out.println("welcome"); return; } else if (!userguess.equals("test")) { system.out.println("wrong, try again"); break; } } } }
i think trying create solution, checks 10 times password , exit. if so, recomend mcgee's way proceed forward.
otherwise, issue code loop never continue after first iteration due 'return' or 'break' encountering in control flow.
even though fixed (may removing of those); program go infinite loop; while loop aways have true case (x == 10).
please let know, goal; more.
Comments
Post a Comment