首页 > 编程语言 >程序清单3_6

程序清单3_6

时间:2023-02-05 17:48:24浏览次数:38  
标签:BigInteger java Scanner int System 程序清单

package java_hexin;

import java.math.BigInteger;
import java.util.Scanner;

public class j3_6 {
    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 numbers 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("You odds are 1 in " + lotteryOdds + ". Good luck!");
    }
}

标签:BigInteger,java,Scanner,int,System,程序清单
From: https://www.cnblogs.com/arciab/p/17093677.html

相关文章

  • 程序清单3_7
    packagejava_hexin;importjava.util.Arrays;importjava.util.Scanner;publicclassj3_7{publicstaticvoidmain(String[]args){Scannerin=......
  • 程序清单3_9
    packagejava_hexin;publicclassj3_9{publicstaticvoidmain(String[]args){finalintNMAX=10;int[][]odds=newint[NMAX+1][];......