The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Java Loop
By Guest on 14th September 2017 12:51:19 PM | Syntax: JAVA | Views: 47



New paste | Download | Show/Hide line no. | Copy text to clipboard
  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.        
  9.         public static int factorial(int n)
  10.         {       int result = 1;
  11.                 for(int i = 2; i <= n; i++)
  12.                         result *= i;
  13.                 return result;
  14.         }
  15. }



  • Recent Pastes