美文网首页
3.9大数值

3.9大数值

作者: 十六只猴子王 | 来源:发表于2019-03-11 20:13 被阅读0次

基本的整数和浮点数精度不过,可以使用java.math包中的BigInteger和BigDecimal

  • BigInteger add(BigInteger other
  • BigInteger subtract(BigInteger other)
  • BigInteger multiply(BigInteger other)
  • BigInteger divide(BigInteger other)
  • BigInteger mod(BigInteger other)
    返回这个大整数和另一个大整数的和差积商余
  • int compareTo(BigInteger other)
    这个大整数和另一个大整数相等返回0;大于返回正数;小于返回负数
    *static BigInteger valueOf(long x)
    返回值等于x
  • 四舍五入方法:java.Math.roundingMode.HALF_UP
import java.math.*;
import java.util.*;
public class BigIntegerTest
{
   public static void main(String[] args)
   {
      Scanner in = new Scanner(System.in);

      System.out.print("How many numbers do you need to draw? ");
      int k = in.nextInt();

      System.out.print("What is the highest number you can draw? ");
      int n = in.nextInt();

/*
*计算二项式系数n*(n-1)*(n-2)*…(n-k+1)/(1*2*3*…*k)
*/

      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("Your odds are 1 in " + lotteryOdds + ". Good luck!");
   }
}

相关文章

  • Excle常用函数

    常用加减乘除用法公式 =数值1+数值2=数值1-数值2=数值1*数值2=数值1/数值2 常用函数及用法 sum 求...

  • 数值分析:数值积分与数值微分

    1 数值积分概述 1.1 引言   对于许多实际问题的求解往往需要计算积分。在高等数学中计算积分采用的是著名的牛顿...

  • 数值单位和数值

    一、长度单位 1.1 绝对单位 absolute units 1.1.1 px pixel 像素是一个绝对单位,这...

  • 数值

    数值 // absolute 绝对值Math.abs(5);Math.abs(-5); // 5 // round...

  • 数值

    JavaScript 内部,所有数字都是以64位浮点数形式储存,即使整数也是如此。所以,1与1.0是相同的,是同一...

  • 数值

    概述 整数和浮点数 JavaScript 内部,所有数字都是以64位浮点数形式储存,即使整数也是如此。所以,1与1...

  • 数值

    163 整型3.14 浮点型2.5e11 科学计数法形式0xfa1b 16进制形式 运算 1 + 21 - 21 ...

  • 数值

    Math.roundMath.round(1.1) // => 1 Math.ceilMath.ceil(1.1...

  • 数值

    数值的表示二进制表示法新写法: 前缀 0b 或 0B 。 八进制表示法新写法: 前缀 0o 或 0O 。 常量Nu...

  • 非数值转化为数值

    有三个函数可以把非数值转化为数值 Number () parseInt () parseFloat () Numb...

网友评论

      本文标题:3.9大数值

      本文链接:https://www.haomeiwen.com/subject/mfpbpqtx.html