public class Factorial2{

   public static long factorial(int number) {
       long result = 1L;
       
       if(number == 0 || number == 1) {
		return 1L;
	} else {
		result = number * factorial(number - 1);
		return result;
	}

   }
   
   public static void main(String[] argv) {

int[] tab = {0,1,2,3,4,5,6,7,8,9};
for(int i : tab){
    long out = factorial( i );
    System.out.println("n = "+  i + "  n! = " + out);
}
   }

}

タグ:

+ タグ編集
  • タグ:
最終更新:2020年06月27日 22:09