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);
        }
    
  • 相关阅读:
    页码数求0到9共有多少个
    reduce
    map,filter
    匿名函数 lambda
    递归
    python 切片
    函数
    集合(set)
    python 中random 库的使用
    printf 输出?
  • 原文地址:https://www.cnblogs.com/custoyth/p/13366180.html
Copyright © 2011-2022 走看看