Wikipedia:Bak pasir: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
k Bot: Dibersihkan secara otomatis |
Tidak ada ringkasan suntingan Tag: Suntingan perangkat seluler Suntingan peramban seluler |
||
Baris 1:
<!-- package sample;
/**
* 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
*/ -->
|