Back to notes -- Keyboard shortcut: 'u'              Lecture 5 - slide 6 : 28
Program 1
 

import cs1.*;

class FakultetsDemo3{

 static final int SIDSTE = 13;

 static int fak(int n){
   return 
     n == 0 ? 1 : n * fak(n-1);
 }

 public static void main(String args[]){
   long[] fakultet = {0,fak(1),fak(2),fak(3),fak(4),fak(5),fak(7),
                      fak(8),fak(9),fak(10),fak(11),fak(12)};
   int n;
   do {
     System.out.println("Opslå fakultet af (0 afslutter):");
     n = Keyboard.readInt();
     if (n > 0) System.out.println(fakultet[n]);
   } while (n != 0);
 }
}