Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Opgavebeskrivelse: Skriv en rekursiv metode (factorial(5)), som beregner factorial af n=5.
- private static int factorial(int n) {
- if (n > 0) {
- if (n == 1) return 1;
- else {
- return n * factorial(n - 1);
- }
- } else return(0);
- }
- public static void main(String[] args) {
- System.out.println("Result is " + factorial(5) + ".");
- }
Add Comment
Please, Sign In to add comment