-5

I have an issue when I run this program, If I use int it works, but for string it does not.

import java.util.Scanner;

public class userinput_swutch_do_while {

    public static void main(String[] args) {    

        String password= null;
        Scanner value = new Scanner(System.in);
        do {
            System.out.println("Enter the password for ATM: ");
            password = value.nextLine();
            System.out.println("You put : "+password);

        } while  (password !="55");


        System.out.println("You got it!");

    }

}
kourouma_coder
  • 1,078
  • 2
  • 13
  • 24
Raj Ib
  • 1
  • 4
    Possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Elliott Frisch Mar 28 '17 at 22:41

1 Answers1

0

In JAVA, String equality is tested correctly using equals()or equalsIgnoreCase();
That being said, you can try this :

import java.util.Scanner;

public class userinput_swutch_do_while {

public static void main(String[] args) {    

    String password= null;
    Scanner value = new Scanner(System.in);
    do {
        System.out.println("Enter the password for ATM: ");
        password = value.nextLine();
        System.out.println("You put : "+password);

    } while(!(password.equals("55")));// string equality 


    System.out.println("You got it!");

  }

 }
kourouma_coder
  • 1,078
  • 2
  • 13
  • 24