title: java recursion and class object with factorial
body: <p>i was assigned a problem to write a program using recursion, which is working properly, my only question is that it was specified to create a class object to do the factorial calculation instead of method...am I doing this right?</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Assignment2A {
  
  public static void main(String[] args){ 
      Scanner scan = new Scanner(System.in); //sets up scanner
      boolean correct = true;             //sets up boolean operation
      while(true){
      try{                                //try catch operation
          System.out.println("Welcome to the factorial function");
          System.out.println("Please enter a number or press 0 to exit");
          long startTime =System.nanoTime();
          System.out.println("Start Time: "+startTime+" nanoseconds."); //display the start time
  
          int n = scan.nextInt();             //scans the input
          int factorial= fact(n);             
          System.out.println("The Factorial of the number entered is: " + factorial);
  
          long taskTime = System.nanoTime() - startTime;
          System.out.println("Task Time: "+taskTime+" nanoseconds.\n\n");
  
      }catch(Exception e){                //checks if the input is a string or character
          System.out.println("That is not a number!");    //displays that the input is invalid
          long startTime =System.nanoTime();
          long taskTime = System.nanoTime() - startTime;
          System.out.println("Task Time: "+taskTime+" nanoseconds.");
          System.exit(0);         //exits the program
          }
      }
  }
  
  static int fact(int n){
  int output;                 //sets the output as int
  long startTime = System.nanoTime();     //gets the start time of the cpu
  long taskTime = System.nanoTime()-startTime;    //gets the task time
  if (n==0){                      //if the input is 0, system exits
      System.out.println("Exiting Program");      
      System.out.println("Task Time: "+taskTime+ " nanoseconds."); //displays cpu time
      System.exit(0);
  }
  else if(n==1){
      return 1;           //if input is 1, the factorial of 1 is 1
  }
  output = fact(n-1)*n;   //recursive method for factorial
    return output;
   }
  }
  </code></pre>