• java 10000的阶乘


    package test;
    import java.math.BigInteger;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    public class MyTest {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            List<Integer> result = new ArrayList<Integer>();
            int carry = 0;
            int digit = 1;
            int temp = 1;
            int i,j;
            result.add(1);
            for(i = 2;i<=n;i++){
                for(j = 0,carry = 0;j<digit;j++){
                    temp = result.get(j)*i+carry;
                    result.set(j, temp%10000);
                    carry  = temp/10000;
                }
                
                while(carry != 0){
                    result.add(digit++, carry%10000);
                    carry/=10000;
                }
            }
            int count = 1;
            System.out.print(result.get(digit-1));
            for(i = digit-1;i>=1;i--){
                count++;
                if(result.get(i-1)<10){
                    System.out.print("000");
                }else if(result.get(i-1)<100){
                    System.out.print("00");
                }else if(result.get(i-1)<1000){
                    System.out.print("0");
                }
                System.out.print(result.get(i-1));
                
            }
        }
    }        
  • 相关阅读:
    01--DNS服务器3
    01--DNS服务器2
    装配bean
    实现二级域名
    apache反向代理
    struts拓展restful
    restful是什么
    struts的声明式异常处理
    linux常用命令之压缩打包
    linux常用命令之文件系统
  • 原文地址:https://www.cnblogs.com/mophy/p/9684085.html
Copyright © 2020-2023  润新知