Advertisement
vp0415

lec4.1

Oct 31st, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FactorialToTwenty {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner input = new Scanner(System.in);
  7.         long factorial = 1;
  8.         for(factorial = 1; factorial < 20; factorial++)
  9.         {
  10.             System.out.print("n = ");
  11.             int n = input.nextInt();
  12.             do {
  13.                 factorial *= n;
  14.                 n--;
  15.                 }
  16.                 while (n > 0);
  17.                 System.out.println("n! = " + factorial);
  18.            
  19.         }
  20.  
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement