/* * Run this as: * java Factorial */ public class Factorial { public static void main(String[] args) { int x = factorial(5); System.out.println(x); int y = factorial(10); System.out.println(y); System.out.println(factorial(3)); } /* * Here is a subroutine defined. In Java, we call it a method. */ public static int factorial(int x) { if (x == 0) { return 1; } return x * factorial(x - 1); } }