Created
January 1, 2024 05:20
Contoh kode faktorial menggunakan rekursif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Faktorial { | |
public static int hitungFaktorial(int n) { | |
if (n == 0) { | |
return 1; | |
} else { | |
return n * hitungFaktorial(n - 1); | |
} | |
} | |
public static void main(String[] args) { | |
int n = 5; | |
int hasilFaktorial = hitungFaktorial(n); | |
System.out.println("Faktorial dari " + n + " adalah " + hasilFaktorial); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment