0

Hi I want to implement a while loop where users can input some strings and finish it by entering an empty String. When I am entering for example "Hello", "World", "" the loop does continue infinitely, but it should stop after the empty string - I don`t know why. Can you help?

Maybe the check if the string is unequal an empty string does`t work?

This is my code:

public static void main(String[] args) {
    write("Enter some words and end your input by an empty string.");
    String input = readString("Input a word:");
    while(input != "") {
        input = readString("word:");
    }

Thank you.

Z.Wo
  • 101
  • 2
  • 10
  • Actually I don`t think that it is a duplicate because the "!=" is not the problem. – Z.Wo Nov 19 '17 at 18:01
  • I`ve got the answer to my question: I need to compare it like the following: while(input.length() != 0){ input = readString(...)} but thank you though – Z.Wo Nov 19 '17 at 18:47

0 Answers0