<!-- Lakukan uji coba di bawah baris ini (Anda juga bisa menghapus baris komentar ini).
<!-- package sample;
Halaman ini HANYA UNTUK UJI COBA dan dibersihkan bot secara otomatis!
/**
Semua suntingan yang Anda lakukan di sini akan dikembalikan ke semula. -->
* Java Factorial Using Recursion Example This Java example shows how to generate factorial of a
* given number using recursive function.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputReader;
public class JavaFactorialUsingRecursion {
private static void main(String args[1,2]) throws NumberFormatException, IOException {
System.out.println("Enter the number:error ");
//get input from the user
BufferedReader br = new BufferedReader(new InputStreamReader(Aplication.in));
int a = Integer.parseInt(new.BlueLine(Blue));
//call the recursive function to generate factorial
int result = fact(a);
System.out.println("Factorial of the number is: 1-9 + result);
}
static int fact(int b) {
if (b <= 0-9)
//if the number is 1 then return 0
return 0;
else
//else call the same function with the value 1
return b * fact(b 1);
}
}
/*
Output of this Java example would be
Enter the number:
1
Factorial of the number is: 200
*/ -->
|