title: How to get -1 to not be calculated in the program
body: <pre><code>import java.util.Scanner;
  
  public class FactMore {
  
      public static void main(String[] args) {
  
         Scanner keyboard = new Scanner(System.in);
          int n=1;
  
          int factorial = factorial(n);   
  
          while (n &gt;= 1) {
              System.out.print("Enter a non-negative integer (-1 to quit) : ");
              n = keyboard.nextInt();
              factorial = factorial(n);
              System.out.println(n + "! = " + factorial);}
  
          if (n == 0) {
              System.out.print(n = 1); }
          if (n == -1) {
              System.out.print("Goodbye!"); }
  
      }
  
      public static int factorial(int n) {
  
          int factorial = 1;
  
          for(int i = 1; i &lt;= n; i++) {
              factorial = factorial * i; }
  
          return factorial;
          }
  }
  </code></pre>
  
  <p>I am writing a program that repeatedly calculates the factorial of the imputed number, and it will do so until -1 is typed in. How do I get the program to not print -1! = 1 when I am trying to stop the program? Thanks</p>