loop code


SUBMITTED BY: shashi9985

DATE: Aug. 23, 2016, 7:41 a.m.

FORMAT: Text only

SIZE: 324 Bytes

HITS: 2986

  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. }

comments powered by Disqus