首页 > 编程语言 > 详细

Java 随机抽奖

时间:2016-12-26 21:53:57      阅读:348      评论:0      收藏:0      [点我收藏+]

package Third;

import java.util.Scanner;

public class LotteryOdds {

public static void main(String[] args) {
// TODO Auto-generated method stub
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();

int lotteryOdds = 1;
for(int i =1;i<=k;i++){
lotteryOdds = lotteryOdds*(n-i+1)/i;
System.out.println("Your odds are 1 in "+lotteryOdds+".Good luck");
}
}

}

Java 随机抽奖

原文:http://www.cnblogs.com/guo-809264853/p/6223842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!