No, you created a method, fact(int n) that calculates the factorial.
You should create a new class with a method that calculates the factorial. An object of the class would be instantiated and then, the method that calculates the factorial would be invoked from the class object.
Example:
// outside the while loop instantiate your class object for
// dealing with factorial computations
Factorial factorial = new Factorial();
// inside the while loop, instantiate your method for
// computing factorial of "n", invoking your factorial
// computation method that is defined inside your class
int result = factorial.computeFactorial(n);