zoukankan      html  css  js  c++  java
  • java基础 大数类

    BigInteger和BigDecimal是util包下面的两个类。

    他们能处理任意长度的整数和实数。

    静态方法valueof()能把primitive转换成对应的大数对象。

    加减乘除必须使用对应对象的方法。

    两个大数比较要使用compareto方法。

    public static void main(String[] args) {
            Scanner in  = new Scanner(System.in);
    
            System.out.println("how many numbers do you need to draw?");
            int k = in.nextInt();
    
            System.out.println("What is the highest number you can draw?");
            int n = in.nextInt();
    
    
            BigInteger lotteryOdds = BigInteger.valueOf(1);
    
            for(int i = 1; i <= k; i ++) {
                lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n-i+1) . divide(BigInteger.valueOf(i)));
            }
            System.out.println(lotteryOdds);
        }
    
  • 相关阅读:
    MathML
    Redux counterpart rematch dva
    flow
    pauseable 库
    a simple machine learning system demo, for ML study.
    react图工具集成
    SQLite
    Celery
    RabbitMQ installation
    Thunk
  • 原文地址:https://www.cnblogs.com/custoyth/p/13366180.html
Copyright © 2011-2022 走看看