title: Java - while loop not working as expected
body: <p>I am working with a fairly basic programming task in Java. We are asked to create a chat-robot, where the robot is to answer randomly from a set of given strings until the user writes "Bye!", where the robot will simply reply with "Bye!" and end the program. I've written the following code:</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Random;
  
  public class Robot {
  
  public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      Random random = new Random();
  
      String[] answer = new String[6];
      answer[0] = "blabla1";
      answer[1] = "blabla2";
      answer[2] = "blabla3";
      answer[3] = "blabla4";
      answer[4] = "blabla5";
      answer[5] = "blabla6";
      boolean keepGoing = true;
  
  
      System.out.println("Hello, how can I help you?");
      while (keepGoing) {
          String input = in.next();
          int output = random.nextInt(6);
          System.out.println(answer[output]);
  
          if (input.equals("Bye!")){
              keepGoing = false;
              System.out.println("Bye!");
          }
  
      } 
  
  }
  </code></pre>
  
  <p>I have two issues with the program:</p>
  
  <ol>
  <li>At times, seemingly at random, the program will answer with multiple strings.</li>
  <li>When writing "Bye!", the program throws in another string before writing "Bye!". I do know that this may be resolved by adding "break;", but I'd consider this bad practice seeing as I am already using a boolean. (I'd like to keep using it.)</li>
  </ol>
  
  <p>I have no idea as to why these errors occur. </p>