Examples of smaller Java programs that do various interesting things.

123456789101112131415
  1. public class Factorial
  2. {
  3. public static void main(String[] args)
  4. { final int NUM_FACTS = 100;
  5. for(int i = 0; i < NUM_FACTS; i++)
  6. System.out.println( i + "! is " + factorial(i));
  7. }
  8. public static int factorial(int n)
  9. { int result = 1;
  10. for(int i = 2; i <= n; i++)
  11. result *= i;
  12. return result;
  13. }
  14. }