Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. problem in do-while loop

problem in do-while loop

Scheduled Pinned Locked Moved Java
helpjavaquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kenna180
    wrote on last edited by
    #1

    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!!"); } }

    R 1 Reply Last reply
    0
    • K kenna180

      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!!"); } }

      R Offline
      R Offline
      raheela123
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • R raheela123

        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

        K Offline
        K Offline
        kenna180
        wrote on last edited by
        #3

        oic! Thank you very much!! :laugh:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups