package class6_1_Factorial; import java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter a number to take the factorial of: (Q to quit)"); while(in.hasNextInt()) { int value = in.nextInt(); System.out.println("factorial(value) = " + factorial(value)); } } private static int factorial(int value) { if(value < 0) { throw new IllegalArgumentException("Cannot take factorial of negative numbers"); } if(value == 0) { return 1; } else { return value * factorial(value - 1); } } }