Java Do and While validation -
i created simple program there password, reason if input password program carry on executing though used , while.
import java.util.scanner; public class passcheck { double password; int userinp; public void validation() { do{ system.out.println("please enter password"); scanner in = new scanner(system.in); int password = in.nextint(); } while (password == 1111); system.out.println("please select whether workout area or perimeter"); system.out.println("enter 1 area , enter 2 perimeter"); scanner in = new scanner(system.in); int userinp = in.nextint(); switch (userinp){ case 1: circlearea circleareaobject = new circlearea(); circleareaobject.area(); case 2: } } }
your int password assign valid inside brackets of { ... } block. in while, referencing double password never 1111.
do{ system.out.println("please enter password"); scanner in = new scanner(system.in); int password = in.nextint(); // "password"... } while (password == 1111); // not same variable this...
in while(password = 1111) referencing double password (as mentioned, why double? ). cannot reference local int password here, since it's scope limited insides of brackets above.
Comments
Post a Comment