1

having problems ending this loop when I type "quit"

String employee=" ";
double pay;
int hours;
   while(employee != "quit")
 {
    System.out.print("Enter employee name: ");
    employee = input.next();

    System.out.print(employee);
    System.out.println("\n");
}
Alex
  • 119
  • 3
  • 9
  • Don't compare Strings using `==` or `!=`. Use the `equals(...)` or the `equalsIgnoreCase(...)` method instead. Understand that `==` checks if the two *object references* are the same which is not what you're interested in. The methods on the other hand check if the two Strings have the same characters in the same order, and that's what matters here. – Hovercraft Full Of Eels Sep 03 '16 at 22:03
  • So instead of `while(employee != "quit")`, consider doing `while(!"quit".equalsIgnoreCase(employee))` – Hovercraft Full Of Eels Sep 03 '16 at 22:04
  • You also may or may not mean `print(employee); println("\n");`: this can also be written as `println(employee); println();`, if you really intend to insert a newline after each employee; or `println(employee);` if you don't want the newline. – Andy Turner Sep 03 '16 at 22:06

0 Answers0