/* The program uses recursive to find the factorial * */ import java.util.*; public class Factorial { public static void main(String[] args) { Scanner key = new Scanner(System.in); int number; // Gets the number from the user System.out.println("Enter a nonnegative integer: "); number = key.nextInt(); /* Pass number into factorial method outputs the factorial * */ System.out.println(number + "!" + " is " + factorial(number)); } // Recursive method private static int factorial(int n) { // Base class if(n==0) { return 1; } else return n*factorial(n-1); } }