Advertisement
Guest User

factorial

a guest
Feb 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package factorial;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Fact
  6. {
  7.     public static void main(String [] arg)
  8.     {
  9.         Scanner keyboard = new Scanner(System.in);
  10.         System.out.println("Enter a number.");
  11.        
  12.         int input, factor, input2;
  13.         String answer = "";
  14.        
  15.         input = keyboard.nextInt( );
  16.         for (input2 = input - 1; input2 >= 1; input2--)
  17.             for (factor = (input * input2) * (input2 - 1); input2 >= 1; input2--)
  18.         {
  19.         if (input2 >= 1)
  20.             System.out.print(factor);
  21.         System.out.println( );
  22.        
  23.         System.out.println("Would you like to continue? (y/n)");
  24.         answer = keyboard.nextLine();
  25.         if (answer == "y")
  26.             System.out.println("Enter a number.");
  27.         input = keyboard.nextInt( );
  28.         }
  29.        
  30.        
  31.        
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement