public class Factorial1{

   public static long factorial(int number) {
       long result = 1;

       for (int factor = number; factor >= 2; factor--) {
           result *= factor;
       }

       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日 17:11