集册 Java实例教程 使用递归的阶乘

使用递归的阶乘

欢马劈雪     最近更新时间:2020-01-02 10:19:05

432
使用递归的阶乘

 

import java.io.BufferedReader;

import java.io.IOException;/* 来 自 nowjava - 时  代  Java*/

import java.io.InputStreamReader;

 

public class Main {

       

        public static void main(String args[]) throws NumberFormatException, IOException{

                int a = 10;

                int result= fact(a);

                System.out.println("Factorial of the number is: " + result);

        }

       

        static int fact(int b)

        {

                if(b <= 1)/* from n o w j a v a . c o m*/

                        //if the number is 1 then return 1

                        return 1;

                
展开阅读全文