大数值

API

java.math.BigInteger

BigInteger add(BigInteger other)

BigInteger subtract(BigInteger other)

BigInteger multiply(BigInteger other)

BigInteger divide(BigInteger other)

BigInteger mod(BigInteger other)

int compareTo(BigInteger other)

static BigInteger valueOf(long x)

 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 
 5 public class BigIntegerTest {
 6 
 7     /**
 8      * @param args
 9      */
10     public static void main(String[] args) {
11         // TODO Auto-generated method stub
12 
13         Scanner in = new Scanner(System.in);
14         
15         System.out.print("How many numbers do you need to draw?");
16         int k = in.nextInt();
17         
18         System.out.print("What is the highest number you can draw?");
19         int n = in.nextInt();
20         
21         BigInteger lotteryOdds = BigInteger.valueOf(1);
22         
23         for(int i = 1;i<k;i++) {
24             lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n-i+1)).divide(BigInteger.valueOf(i));
25             
26             System.out.println("your odds are 1 in "+lotteryOdds+".Good luck!!");
27         }
28     }
29 
30 }
原文地址:https://www.cnblogs.com/linst/p/4966456.html