/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code23octf18recur; import java.util.Random; import java.util.Scanner; /** * * @author jcmtiernan */ public class Code23OctF18Recur { /** * @param args the command line arguments */ public static void main(String[] args) { int count; long value; Random rand = new Random(); /* ** Generate random number using Math.random * Math.random generates a double between 0 and 1 so * multiply the value by something to increase the range count = (int) (Math.random() * 20); */ /* ** Generate random number using Random class * Create an object of the Random class (rand in this example) * use the methods of the Random class to generate ints or doubles * .nextInt method can have an upper bound given in parentheses (20) */ count = rand.nextInt(20); System.out.println("Random input for factorial is "+count); //Scanner input = new Scanner(System.in); //System.out.println("Enter a value to take the factorial of: "); //count = input.nextInt(); value = fact(count); System.out.println("The factorial of "+count+" is "+value); } public static long fact(int k) { long temp; if (k > 0) { temp = k * fact(k - 1); System.out.println("for k = "+k+" temp is "+temp); return temp; } return 1; } }