If you want this to be in a separate class, just encapsulate your fact() method in a new class. Note, however, that your printout of the time taken is incorrect - it merely computes the time for the final entry into the recursive method.
public class Factorial {
public static int compute( int val ) {
long startTime = System.nanoTime();
int result = fact( val );
long taskTime = System.nanoTime()-startTime;
System.out.println("Task Time: "+taskTime+ " nanoseconds.");
}
protected static int fact( int val ) {
if (n==1){
return val;
}
return fact(val-1)*val;
}
}
then in you main,
int answer = Factorial.compute(value);