title: how to apply system exit when pressing 0
body: <p>so i have this factorial program that accepts input by the user. everything is working fine but I'm trying to figure out how to end the program by inputting 0. Since it's on a boolean operation i can't input an if statement because i would get a compile error.   </p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Assignment2A {
  
      public static void main(String[] args){ 
          Scanner scan = new Scanner(System.in);
          boolean correct = false;
          while(!false){
              try{
                  System.out.println("Welcome to the factorial function");
                  System.out.println("Please enter a number or press 0 to exit");
                  int n = scan.nextInt();
                  // if(n=0){
                  // System.exit(0);
                  //}
                  int factorial= fact(n);
                  System.out.println("The Factorial of the number entered is: " + factorial);
                  correct = true;
              }catch(Exception e){
                  System.out.println("That is not a number!");
                  System.exit(0);
              }
          }
      }
  
      static int fact(int n){
          int output;
          if(n==1){
              return 1;
          }
          output = fact(n-1)*n;
          return output;
      }
  }
  </code></pre>