problem in do-while loop
-
The loop cant be stop eventho the key-in matches. Can anyone fix this and tell me my mistake? Greatly appreciate it if so!
import java.io.*; public class A { public static void main(String args[]) throws IOException { BufferedReader stdin=new BufferedReader (new InputStreamReader(System.in)); //char n,p; String name,pwd; int n1; int p2; System.out.println("\tWelcome to "); System.out.println("*******SHINE IT Training Centre*******"); System.out.println("**Please login before u calculate**"); do { System.out.println("Enter user name: "); name=stdin.readLine(); n1=Integer.parseInt(name); System.out.println("Enter password: "); pwd=stdin.readLine(); p2=Integer.parseInt(pwd); //System.out.println("Incorrect input!!"); } while ((name!="2208")&&(pwd!="1234")); System.out.println("Successful Login!!"); } }
-
The loop cant be stop eventho the key-in matches. Can anyone fix this and tell me my mistake? Greatly appreciate it if so!
import java.io.*; public class A { public static void main(String args[]) throws IOException { BufferedReader stdin=new BufferedReader (new InputStreamReader(System.in)); //char n,p; String name,pwd; int n1; int p2; System.out.println("\tWelcome to "); System.out.println("*******SHINE IT Training Centre*******"); System.out.println("**Please login before u calculate**"); do { System.out.println("Enter user name: "); name=stdin.readLine(); n1=Integer.parseInt(name); System.out.println("Enter password: "); pwd=stdin.readLine(); p2=Integer.parseInt(pwd); //System.out.println("Incorrect input!!"); } while ((name!="2208")&&(pwd!="1234")); System.out.println("Successful Login!!"); } }
eigther change while ((name!="2208")&&(pwd!="1234")); to while ((!name.equals("2208"))&&(!pwd.equals("1234"))); or while ((n1!=2208)&&(p2!=1234)); ;P ;P ;P ;P
-
eigther change while ((name!="2208")&&(pwd!="1234")); to while ((!name.equals("2208"))&&(!pwd.equals("1234"))); or while ((n1!=2208)&&(p2!=1234)); ;P ;P ;P ;P