How to use Nested for Loop in java?

public class MainClass {
public static void main(String[] args) {
long limit = 6L;
long factorial = 1L;

for (long i = 1L; i <= limit; i++) {
  factorial = 1L;

  for (long factor = 2; factor <= i; factor++) {
    factorial *= factor;
  }
  System.out.println(i + "! is " + factorial);
}

}
}
1! is 1
2! is 2
3! is 6
4! is 24
5! is 120
6! is 720