الدوال التكرارية Java 18- recursive method
import javax.swing.JOptionPane;public class App{//function recursive/* modificateur type funct( type params){funct(params);} */// n! = n*(n-1)*(n-2)* ..... *2*1// 0! = 1static int fact(int n){if(n<=0) return 1;else return n*fact(n-1); // n*(n-1)*fact(n-2)// n*(n-1)*(n-2)*fact(n-3)// n*(n-1)*(n-2)*(n-3)*.......*2*1}public static void main(String[] args) {JOptionPane.showMessageDialog(null, fact(5)); // 120}}
0 تعليقات