If you want to make a class object then remove static from your method
Also it would be better if you use dynamic programming approach for solving this problem.
import java.util.*;
import java.io.*;
public class Assignment2A {
public static void main(String[] args){
Assignment2A x = new Assignment2A();
x.askForOutput();
}
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;
}
public void askForOutput(){
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
}
}
}
}