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: 117



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
  • Demo
    2 days 16 hours 18 mins 48 secs ago
  • Real
    2 days 22 hours 43 mins 25 secs ago
  • OZ MagicCity Drumkit
    3 days 13 hours 54 mins 36 secs ago
  • Masodjko
    6 days 10 hours 49 mins 10 secs ago
  • Test title
    1 week 5 days 12 hours 12 mins and 16 secs ago